firebase-tools:
8.4.3
Platform:
Windows 10
import * as functions from 'firebase-functions'
exports.onDeviceOnlineChanged = functions.database.ref('/status/{deviceId}')
.onWrite(async (change, context) => {
const ref = change.before.ref.toString()
// do something with the reference
return ref
})
make a change to that node on the realtime database to initiate the function
No error, this works on the server, but not on the emulator.
Calling the same code directly from the app runs without issues. The call to the change.before.ref causes the error only when the function is initiated from a trigger.
Calling using the initiated admin.database().ref('/status/${deviceId}') works normally as in the snippet below
exports.onDeviceChanged = functions.https.onCall(async (data, context) => {
const deviceId = data.deviceId
const status = admin.database().ref(`/status/${deviceId}`)
const deviceFirestoreRef = admin.firestore().collection('devices').doc(deviceId)
const upd = { online: status.toJSON() }
return deviceFirestoreRef.update(upd);
})
throws the error:
@firebase/database: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://
! functions: Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com
at fatal (C:\dev\xyz\functions\node_modules\@firebase\database\dist\index.node.cjs.js:341:11)
at parseRepoInfo (C:\dev\xyz\functions\node_modules\@firebase\database\dist\index.node.cjs.js:1295:9)
at RepoManager.databaseFromApp (C:\dev\xyz\functions\node_modules\@firebase\database\dist\index.node.cjs.js:14919:25)
at Object.initStandalone (C:\dev\xyz\functions\node_modules\@firebase\database\dist\index.node.cjs.js:15303:45)
at DatabaseService.getDatabase (C:\dev\xyz\functions\node_modules\firebase-admin\lib\database\database.js:66:23)
at FirebaseApp.database (C:\dev\xyz\functions\node_modules\firebase-admin\lib\firebase-app.js:231:24)
at DataSnapshot.get ref [as ref] (C:\dev\xyz\functions\node_modules\firebase-functions\lib\providers\database.js:279:34)
at C:\dev\xyz\functions\lib\presense.js:7:31
at cloudFunction (C:\dev\xyz\functions\node_modules\firebase-functions\lib\cloud-functions.js:132:23)
at C:\Users\P\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:563:20
! Your function was killed because it raised an unhandled error.
@carrickpaul thanks for reporting this and for the clear reproduction steps, we should be able to fix this but it may require some changes in the Database SDK itself (which seems to be the source of the stack trace)
I was able to reproduce this issue, will dig into the cause.
Hmmm in the debugger I am seeing snap.instance="https://fir-dumpster.localhost" which is definitely not correct (fir-dumpster is my project ID).
Ah this is actually a bug in the firebase-functions SDK:
https://github.com/firebase/firebase-functions/blob/ffd268abd4eedc9e7166f96cae4459191d7e147c/src/providers/database.ts#L307
We can see that this line will produce the awkward .localhost domain:
https://github.com/firebase/firebase-functions/blob/ffd268abd4eedc9e7166f96cae4459191d7e147c/src/providers/database.ts#L325
Ok @carrickpaul I was able to track down this issue. Fixing it would require changes in both the Functions emulator and the Firebase Functions SDK:
Functions SDK Fix: https://github.com/firebase/firebase-functions/pull/727
Functions emulator fix: https://github.com/firebase/firebase-tools/pull/2434
thanks @samtstern
The fix has been merged in to https://github.com/firebase/firebase-tools/pull/2434 so this will be fixed completely in the next release of firebase-tools (as long as it's used with firebase-functions 3.8.0 or higher)
Thanks a bunch for the fixes posted @samtstern
Even after updating both [email protected], and [email protected], I still get this error, but now from @firebase/database instead (^0.6.0 is pointed to, but still experienced it with a fresh install which pulled 0.6.8 of @firebase/database). This is also being experienced by multiple devs on my team
Here is a snippet of the error:
âš functions: Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com
at fatal (/private-code-path/functions/node_modules/@firebase/database/dist/index.node.cjs.js:341:11)
at parseRepoInfo (/private-code-path/functions/node_modules/@firebase/database/dist/index.node.cjs.js:1295:9)
at RepoManager.databaseFromApp (/private-code-path/functions/node_modules/@firebase/database/dist/index.node.cjs.js:14985:25)
at Object.initStandalone (/private-code-path/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15376:45)
at DatabaseService.getDatabase (/private-code-path/functions/node_modules/firebase-admin/lib/database/database.js:67:23)
at FirebaseApp.database (/private-code-path/functions/node_modules/firebase-admin/lib/firebase-app.js:232:24)
at DataSnapshot.get ref [as ref] (/private-code-path/functions/node_modules/firebase-functions/lib/providers/database.js:293:34)
at ourFunctionName (/private-code-path/)
at process._tickCallback (internal/process/next_tick.js:68:7)
âš Your function was killed because it raised an unhandled error.
(NOTE: Paths have been stripped to a base of private-code-path)
Let me know if you need any more info or would like me to open a new issue
I noticed the same, but a release for firebase-tools hasn't been released
since this update, so from my understanding we just need to wait a while
longer
On Thu, 16 Jul 2020, 00:08 Scott Prue, notifications@github.com wrote:
Thanks a bunch for the fixes posted @samtstern
https://github.com/samtsternEven after updating both firebase-tools, and firebase-functions to the
noted versions, I still get this error, but now from @firebase/database
instead (^0.6.0 is pointed to, but still experienced it with a fresh
install which pulled 0.6.8 of @firebase/database). This is also being
experienced by multiple devs on my teamLet me know if you need any more info or would like me to open a new issue
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-functions/issues/726#issuecomment-659040164,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAKRKQTEIPHJD7PX6X7G42LR3YSHRANCNFSM4OUWD5EQ
.
@ElGoorf You are correct - v8.6.0 of firebase-tools was just released a few minutes go and it appears that fixed it. Got confused since I didn't see 2434 mentioned anywhere in the releases
Thanks @samtstern
@prescottprue the fix in the CLI was actually only released a few hours ago in version 8.6.0 ... before that it was merged to master but not released. Can you try with that version?
Oops didn't see your last comment when replying. Glad it works now!
Most helpful comment
The fix has been merged in to https://github.com/firebase/firebase-tools/pull/2434 so this will be fixed completely in the next release of
firebase-tools(as long as it's used withfirebase-functions3.8.0 or higher)