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

vague error message on newer versions of CLI: "Failed to load function definition from source:..." #1230

Open
kiptoomm opened this issue Aug 31, 2022 · 1 comment

Comments

@kiptoomm
Copy link

kiptoomm commented Aug 31, 2022

[REQUIRED] Environment info

firebase-tools: v10.9.0 to v11.8.0

Platform: macOS

[REQUIRED] Test case

On a project that requires functions.config(), remove the .runtimeconfig.json file from the project and run the functions emulator. Based on the official docs at https://firebase.google.com/docs/functions/local-emulator#web-version-9

[REQUIRED] Steps to reproduce

  1. Create a simple script test.js with the following contents:
const functions = require("firebase-functions");
const { region } = functions.config().functions; 
console.log("my functions region: ", region);
...
// define some cloud functions

// then import test.js in your index.js file

'region' is a sample Functions environment variable whose firebase functions:config:get output looks like this:

  {
  "functions": {
    "region": "us-central1"
  }
 
  1. Run the Functions emulator with debug logging: firebase emulators:start --debug

[REQUIRED] Expected behavior

The cloud functions should run as usual if we had a valid .runtimeconfig.json file.
However, if we legitimately don't have the file locally, the emulator should rightly fail with a helpful error message such as below (which versions 10.8.0 and below produce):

...
[warn] ⚠  It looks like you're trying to access functions.config().functions but there is no value there. You can learn more about setting up config here: https://firebase.google.com/docs/functions/local-emulator {"metadata":{"emulator":{"name":"functions"},"message":"It looks like you're trying to access functions.config().functions but there is no value there. You can learn more about setting up config here: https://firebase.google.com/docs/functions/local-emulator"}}
[warn] ⚠  TypeError: Cannot destructure property 'region' of 'functions.config(...).functions' as it is undefined.
    at Object.<anonymous> (~/functions/test.js:2:9)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:816:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (~/functions/index.js:3:16)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10) {"metadata":{"emulator":{"name":"functions"},"message":"TypeError: Cannot destructure property 'region' of 'functions.config(...).functions' as it is undefined.\n    at Object.<anonymous> (~/functions/test.js:2:9)\n    at Module._compile (node:internal/modules/cjs/loader:1095:14)\n    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)\n    at Module.load (node:internal/modules/cjs/loader:975:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:816:12)\n    at Module.require (node:internal/modules/cjs/loader:999:19)\n    at require (node:internal/modules/cjs/helpers:93:18)\n    at Object.<anonymous> (~/functions/index.js:3:16)\n    at Module._compile (node:internal/modules/cjs/loader:1095:14)\n    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)"}}
[warn] ⚠  We were unable to load your functions code. (see above) {"metadata":{"emulator":{"name":"functions"}}}
...

[REQUIRED] Actual behavior

An error occurs, but the message firebase-debug.log is not as helpful/detailed as in previous versions of the CLI:

...
[error] Error: Failed to load function definition from source: Failed to generate manifest from function source: TypeError: Cannot destructure property 'region' of 'functions.config(...).functions' as it is undefined.
...
@taeold
Copy link
Contributor

taeold commented Sep 12, 2022

The prior version of the Functions Emulator required monkey patching of the Functions SDK, which no longer works. Technically, we are trying to remove all monkey patching of library code as that ended up being unreliable and difficult to maintain.

I'm moving this FR to Functions SDK where I think it should be supported natively w/o relying on monkey patching.

@google-oss-bot
Copy link
Collaborator

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@taeold taeold transferred this issue from firebase/firebase-tools Sep 12, 2022
@taeold taeold removed their assignment Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants