firebase-tools
firebase-tools copied to clipboard
Include more error details on function deploy failure
Before the refactor, function deploys used to include useful error message on failures. E.g.
i functions: creating Node.js 10 function XXX(us-central1)...
i scheduler: ensuring necessary APIs are enabled...
i pubsub: ensuring necessary APIs are enabled...
✔ scheduler: all necessary APIs are enabled
✔ pubsub: all necessary APIs are enabled
Error: HTTP Error: 403, The principal (user or service account) lacks IAM permission "cloudscheduler.jobs.update" for the resource "XXX" (or the resource may not exist).
Now, error messages are hidden behind a generic "Function did not deploy properly" message:
i functions: updating Node.js 10 (Beta) function XXX(us-central1)...
Functions deploy had errors with the following functions:
XXX(us-central1)
To try redeploying those functions, run:
firebase deploy --only "functions:XXX"
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
Users must include --debug flag in order to get the actual error message.
This often makes for support issues (e.g. https://github.com/firebase/firebase-tools/issues/3359) that makes it hard to help the reporter.
You can see more info in firebase-debug.log log file without running with the --debug flag.
We don't really have much control here, all the errors are surfaced from the backend, which is out of our control and often lacking verbosity for technical reasons.
I think we do have access to more useful error messages - they are returned supporting backend services and can be seen as long as you use the --debug flag and are comfortable enough to parse through the dense log messages.
The ask here is to surface those error messages instead of displaying a generic "Error: Functions did not deploy properly." error message. This is doable - think this might make a good issue for first time contributor. I'm happy to help anyone interested in making the necessary changes.
+1 to this. I ran into this problem today when my attempts to deploy a function failed with no message at all. I just got a verbose printout of every function, which was not helpful as I only tried to deploy a single function.
fleker@fleker16:~/samples/project-name$ firebase deploy --only functions:function_name
=== Deploying to 'project-id'...
i deploying functions
⚠ functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions@latest in your functions directory.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔ functions: required API cloudfunctions.googleapis.com is enabled
✔ functions: required API cloudbuild.googleapis.com is enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (2.09 MB) for uploading
i pubsub: ensuring required API pubsub.googleapis.com is enabled...
i scheduler: ensuring required API cloudscheduler.googleapis.com is enabled...
✔ scheduler: required API cloudscheduler.googleapis.com is enabled
✔ pubsub: required API pubsub.googleapis.com is enabled
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 12 function function_name(us-central1)...
✔ functions[function_name(us-central1)]: Successful upsert schedule operation.
i functions: cleaning up build files...
Function URL (unrelated_function(us-central1)): https://us-central1-project-id.cloudfunctions.net/unrelated_function
...
...
Function URL (function_name(us-central1)): https://us-central1-project-id.cloudfunctions.net/function_name
Functions deploy had errors with the following functions:
function_name(us-central1)
To try redeploying those functions, run:
firebase deploy --only "functions:function_name"
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
Having trouble? Try firebase [command] --help
This verbose message provided me with no information as to why it couldn't deploy, which provides me as a developer with no understanding of how to fix.
Once I ran the --debug command, I ended up finding the source of the error buried in the logs, which was my mistake:
Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json
I would definitely prefer this to be brought to the forefront for a much improved developer experience. Having to search through the logs, which are verbose and obscured in JSON strings, can make it hard to identify the true location of the problem.
Going to amend this issue since I ran into the same problem again by mistake and running --debug revealed the error but in a way that is highly obtuse and this provides a weak and confusing developer experience. If you can obtain payloads from apiv2 with an error object, please consider surfacing them in the primary console output so that the developer can quickly identify the source of the problem.
[debug] [2022-08-16T21:13:04.035Z] <<< [apiv2][body] GET https://cloudfunctions.googleapis.com/v1/operations/cG9rZW1vbi1vZi10aGUtd2Vlay91cy1jZW50cmFsMS91c2VfaXRlbS9aLWlmTWdob0Vvdw {"name":"operations/cG9rZW1vbi1vZi10aGUtd2Vlay91cy1jZW50cmFsMS91c2VfaXRlbS9aLWlmTWdob0Vvdw","metadata":{"@type":"type.googleapis.com/google.cloud.functions.v1.OperationMetadataV1","target":"projects/redacted-project/locations/us-central1/functions/use_item","type":"UPDATE_FUNCTION","request":{"@type":"type.googleapis.com/google.cloud.functions.v1.CloudFunction","name":"projects/redacted-project/locations/us-central1/functions/use_item","httpsTrigger":{"url":"https://us-central1-redacted-project.cloudfunctions.net/use_item","securityLevel":"SECURE_OPTIONAL"},"status":"ACTIVE","entryPoint":"use_item","timeout":"60s","availableMemoryMb":256,"serviceAccountEmail":"[email protected]","updateTime":"2022-08-10T15:39:18.011Z","versionId":"328","labels":{"deployment-callable":"true","deployment-tool":"cli-firebase"},"sourceUploadUrl":"https://storage.googleapis.com/uploads-791251748294.us-central1.cloudfunctions.appspot.com/39e1f672-86e0-431b-8889-e38fc0062f7e.zip?GoogleAccessId=service-911249646526@gcf-admin-robot.iam.gserviceaccount.com&Expires=1660686150&Signature=E%2FdTVYtSJo4%2BO%2FmEpM9DNvSK1Hm%2BIAtaxpUFjWP7rH6OV3WWo8ScyjHT1XYlZBQeplwTWiNGdFubL9vF12MSKdeteQsFhUZrIk4cKXAjG3KGGVsAv5qXadiKRtYKb4AKoTOMwkWOTB6oBRMKoAx0xUH4T0%2BVSmc%2F1uMufy4U%2FbXTWzma2T0oGWVLpXuEaP2N%2F2zdCWpAn828%2BTHTil8sWad5DZ9sWrGn76o54pK2dDijmqZLpbHG16Tt7pEghiAEliSSJRdhNWZ90XH1pvKRbzeUfJOiZe9rY0iLA5DFCJToX2I0y%2F6L%2BCTcDOFX3usej5fMwQHSSFeUoSvgYdD8RQ%3D%3D","environmentVariables":{"FIREBASE_CONFIG":"{\"projectId\":\"redacted-project\",\"databaseURL\":\"https://redacted-project.firebaseio.com\",\"storageBucket\":\"redacted-project.appspot.com\",\"locationId\":\"us-central\"}","GCLOUD_PROJECT":"redacted-project"},"runtime":"nodejs14","ingressSettings":"ALLOW_ALL","buildId":"6746f17b-0a96-4dba-b715-a985e46cbdc3","buildName":"projects/911249646526/locations/us-central1/builds/6746f17b-0a96-4dba-b715-a985e46cbdc3","dockerRegistry":"CONTAINER_REGISTRY"},"versionId":"331","updateTime":"2022-08-16T21:12:55Z","buildId":"a232543d-b17a-4271-a501-10f03ec4376e","buildName":"projects/911249646526/locations/us-central1/builds/a232543d-b17a-4271-a501-10f03ec4376e"},"done":true,"error":{"code":3,"message":"Build failed: yarn install v1.22.19\nwarning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.\n[1/5] Validating package.json...\n[2/5] Resolving packages...\nerror Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.\ninfo Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.; Error ID: 12c8ef4a"}}
This is one line of the nearly 600 in my firebase-debug.log file. The error message is buried very deeply in there.
I may consider filing a PR if that's okay.
@Fleker Sorry this issue ended up being unattended for and thanks for offering to do something about it. Happy to review the PR, but also going to earmark this issue as "Good first issue" internally to make it more likely we make progress w/ this issue.
Doing some investigation in the current version, I believe that the logger needs to be updated to info for these errors to show up in the main terminal UI.
https://github.com/firebase/firebase-tools/blob/master/src/deploy/functions/release/index.ts#L96
However, the package-lock.json issue I ran into before doesn't seem to happen anymore likely due to some other firebase-tools fixes. If this ever does happen to me again I will check whether my patch makes sense.