firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

functions:secrets:set fails if a function is unhealthy

Open bkendall opened this issue 2 years ago • 1 comments

[REQUIRED] Environment info

firebase-tools: 11.7.0

Platform: macOS

[REQUIRED] Test case

I have a codebase where I am migrating functions to v2. I accidentally left the old functions.config() code in the top level.

const accessToken = functions.config().particle?.token;

exports.health = onRequest({ region: "us-west1" }, (req, res) => {
  res.status(200).send("ok");
  res.end();
});

I deployed health above, which ultimately failed, but it wasn't that important. Moving forward to other functions, I tried to start adding secrets for them

firebase functions:secrets:set SECRET

[REQUIRED] Steps to reproduce

See above...

[REQUIRED] Expected behavior

I expected the secret to be set, and it turns out it should redeploy functions too.

[REQUIRED] Actual behavior

An error!

[2022-08-17T18:04:19.158Z] >>> [apiv2][query] GET https://cloudfunctions.googleapis.com/v2alpha/projects/x/locations/-/functions [none]
[2022-08-17T18:04:19.837Z] <<< [apiv2][status] GET https://cloudfunctions.googleapis.com/v2alpha/projects/x/locations/-/functions 200
[2022-08-17T18:04:19.837Z] <<< [apiv2][body] GET https://cloudfunctions.googleapis.com/v2alpha/projects/x/locations/-/functions {"functions":[{"name":"projects/x/locations/us-west1/functions/health","buildConfig":{"build":"projects/194637951628/locations/us-west1/builds/643de9a7-cf70-4979-845a-c25b5360b4b9","runtime":"nodejs16","entryPoint":"health","source":{"storageSource":{"bucket":"gcf-v2-sources-194637951628-us-west1","object":"health/function-source.zip"}},"sourceProvenance":{"resolvedStorageSource":{"bucket":"gcf-v2-sources-194637951628-us-west1","object":"health/function-source.zip","generation":"1660754948654035"}}},"state":"FAILED","updateTime":"2022-08-17T16:50:52.288740063Z","labels":{"deployment-tool":"cli-firebase"},"stateMessages":[{"severity":"ERROR","type":"CloudRunServiceNotFound","message":"Cloud Run service projects/x/locations/us-west1/services/health for the function was not found. The function will not work correctly. Please redeploy."}],"environment":"GEN_2"}]}
[debug] [2022-08-17T16:59:53.201Z] TypeError: Cannot read properties of undefined (reading 'service')
    at /Users/bkendall/.nvm/versions/node/v16.16.0/lib/node_modules/firebase-tools/lib/deploy/functions/backend.js:199:113
    at Array.map (<anonymous>)
    at loadExistingBackend (/Users/bkendall/.nvm/versions/node/v16.16.0/lib/node_modules/firebase-tools/lib/deploy/functions/backend.js:199:69)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.existingBackend (/Users/bkendall/.nvm/versions/node/v16.16.0/lib/node_modules/firebase-tools/lib/deploy/functions/backend.js:175:9)
    at async Command.actionFn (/Users/bkendall/.nvm/versions/node/v16.16.0/lib/node_modules/firebase-tools/lib/commands/functions-secrets-set.js:53:25)
[error]
[error] Error: An unexpected error has occurred.

I believe what happened is that the unhealthy function was being looked at and it failed to parse something, crashing the command.

bkendall avatar Aug 17 '22 18:08 bkendall

This usually happens when a function's deployment fails. Deleting such functions from the GCP console will fix your issue.

RazaShehryar avatar Aug 17 '22 20:08 RazaShehryar

Hey @bkendall - Did this solve your issue? If so - I'm also wondering if you think there should be any further action on this issue, or if manually deleting the function from the GCP console is a viable solution to the problem?

russellwheatley avatar Nov 10 '23 15:11 russellwheatley

Good question. I evidently eventually worked around it, but did my duty to file the bug. Probably can close for now.

bkendall avatar Nov 10 '23 16:11 bkendall