Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud function not picking up RTDB emulator when using handler namespace from firebase-functions sdk #2777

Closed
russellwheatley opened this issue Nov 4, 2020 · 4 comments · Fixed by #2810
Assignees

Comments

@russellwheatley
Copy link
Member

russellwheatley commented Nov 4, 2020

[REQUIRED] Environment info

firebase CLI 8.14.1

firebase-tools:

macOS Catalina 10.15.4

Platform:

[REQUIRED] Test case

I've created a repository for the bug with the steps in the README.md file to reproduce: https://github.com/russellwheatley/emulator-extension-issue

[REQUIRED] Expected behavior

I expected the cloud function emulator to run with the RTDB emulator when using the handler namespace of the firebase-functions sdk (apologies if this is in the wrong repo, not sure whose responsibility this falls under).

[REQUIRED] Actual behavior

It doesn't recognise the RTDB emulator. Here is a log from the console:

functions[rtdblimit]: function ignored because the unknown emulator does not exist or is not running.

Let me know if you need more information.

@samtstern
Copy link
Contributor

@russellwheatley thanks for filing this, I thought we had this working. @joehan is this a regression with Extensions emulation?

@joehan
Copy link
Contributor

joehan commented Nov 6, 2020

This looks like it may be a regression - investigating today.

@joehan
Copy link
Contributor

joehan commented Nov 6, 2020

Looking into this closer, i'm not certain this is a regression. @russellwheatley which emulator commands are you using - firebase emulators:* or firebase ext:dev:emulators:*? If you are writing an extension using the handler namespace, you'll need to use firebase ext:dev:emulators:* in order to read function triggers from extension.yaml.

To explain a bit further:

A Cloud Function consists of a trigger (what makes the function fire) and a handler (what to do when the function fires). The 'normal' namespace (functions.database.ref.onCreate) defines both a trigger and a handler, whereas the handler namespace (functions.handler.database.ref.onCreate) only defines a handler. You CAN use the normal namespace for extensions - however, the trigger defined by the code will be ignored in favor of the trigger defined in extension.yaml. This is a bit confusing, so we use the handler namespace to avoid defining a trigger in the code that will be ignored.

Because it doesn't define any triggers in the code, the handler namespace won't work with firebase emulators:exec or firebase emulators:start - these commands don't look at extension.yaml, so handler functions won't have a trigger. Instead, for testing extensions, use firebase ext:emulators:exec <path/to/extension.yaml> or firebase ext:emulators:start <path/to/extension.yaml> - this will pick up triggers from extension.yaml.

Even though I don't think this is a regression, its definitely not a very clear experience right now. At the very least, we probably should add some clearer error messages/warnings for when functions defined using the handler namespace are emulated with firebase emulators:*.

@jthegedus
Copy link
Contributor

jthegedus commented Nov 7, 2020

I am seeing this error with the firebase ext:dev:emulators:exec command but for PubSub triggers:

i  emulators: Starting emulators: functions, pubsub
⚠  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, firestore, database, hosting
⚠  Your requested "node" version "8" doesn't match your global version "12"
⚠  functions: You are not signed in to the Firebase CLI. If you have authorized this machine using gcloud application-default credentials those may be discovered and used to access production services.
⚠  It appears you are running in a CI environment. You can avoid downloading the Pub/Sub Emulator repeatedly by caching the /home/runner/.cache/firebase/emulators directory.
i  pubsub: downloading pubsub-emulator-0.1.0.zip...

i  pubsub: Pub/Sub Emulator logging to pubsub-debug.log
i  functions: Watching "/home/runner/work/<redacted>" for Cloud Functions...
i  functions[testPubSub]: function ignored because the pubsub emulator does not exist or is not running.
i  Running script: npx mocha --exit tests/test.js
npx: installed 100 in 4.5s
testing...123


  0 passing (1ms)

✔  Script exited successfully (code 0)
i  emulators: Shutting down emulators.
i  functions: Stopping Functions Emulator
i  pubsub: Stopping Pub/Sub Emulator
i  hub: Stopping emulator hub

According to the Emulator shutdown logs the PubSub emulator was running as it was stopped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants