Repository navigation
fix(functions): surface unhandled exceptions during functions deployment #11257
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,7 @@ import { | |||||
| parseErrorCode, | ||||||
| } from "./executor"; | ||||||
| import * as ensure from "../ensure"; | ||||||
| import { FirebaseError } from "../../../error"; | ||||||
| import { FirebaseError, getError, getErrStack } from "../../../error"; | ||||||
|
|
||||||
| import { SourceTokenScraper } from "./sourceTokenScraper"; | ||||||
| import { Timer } from "./timer"; | ||||||
|
|
@@ -275,20 +275,37 @@ export class Fabricator { | |||||
| const createAndUpdateResultsArray = await Promise.allSettled(createAndUpdatePromises); | ||||||
|
|
||||||
| // Process results of Phase 1 | ||||||
| const upsertErrors: Error[] = []; | ||||||
| summary.results = createAndUpdateResultsArray.reduce<reporter.DeployResult[]>((acc, r) => { | ||||||
| if (r.status === "fulfilled") { | ||||||
| return [...acc, ...r.value]; | ||||||
| } | ||||||
| // Handle rejection | ||||||
| upsertErrors.push(getError(r.reason)); | ||||||
| logger.debug( | ||||||
| "Fabricator.applyUpserts returned an unhandled exception.", | ||||||
| JSON.stringify(r.reason, null, 2), | ||||||
| getErrStack(r.reason), | ||||||
| ); | ||||||
| return acc; | ||||||
| }, []); | ||||||
|
|
||||||
| await this.cleanupUnusedServiceAccounts(plan, summary.results); | ||||||
|
|
||||||
| // If applyUpserts rejected outside wrapOperation, fail immediately instead of | ||||||
| // proceeding to function deletions with an incomplete result set and exiting 0. | ||||||
| if (upsertErrors.length) { | ||||||
| const opts = | ||||||
| upsertErrors.length === 1 ? { original: upsertErrors[0] } : { children: upsertErrors }; | ||||||
| const msg = | ||||||
| upsertErrors.length === 1 | ||||||
| ? `Fabricator.applyUpserts encountered an unhandled exception: ${upsertErrors[0].message}` | ||||||
| : "Fabricator.applyUpserts encountered unhandled exceptions"; | ||||||
| throw new FirebaseError(msg, { | ||||||
| ...opts, | ||||||
| exit: 2, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using To maintain consistency and adhere to the standard exit codes, consider changing this to
Suggested change
References
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chatted with AI a whole lot about this and it was convinced we should do 2 since it's an unknown internal error and not a user caused error. I defer to @joehan |
||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| const hasFailures = summary.results.some((r) => r.error); | ||||||
|
|
||||||
| if (hasFailures) { | ||||||
|
|
@@ -312,19 +329,36 @@ export class Fabricator { | |||||
| allChangesets.map((changes) => this.applyDeletes(changes)), | ||||||
| ); | ||||||
|
|
||||||
| const deleteErrors: Error[] = []; | ||||||
| const deleteResults = deleteResultsArray.reduce<reporter.DeployResult[]>((acc, r) => { | ||||||
| if (r.status === "fulfilled") { | ||||||
| return [...acc, ...r.value]; | ||||||
| } | ||||||
| deleteErrors.push(getError(r.reason)); | ||||||
| logger.debug( | ||||||
| "Fabricator.applyDeletes returned an unhandled exception. This should never happen", | ||||||
| JSON.stringify(r.reason, null, 2), | ||||||
| getErrStack(r.reason), | ||||||
| ); | ||||||
| return acc; | ||||||
| }, []); | ||||||
|
|
||||||
| summary.results.push(...deleteResults); | ||||||
|
|
||||||
| // If applyDeletes rejected outside wrapOperation, fail instead of returning | ||||||
| // an incomplete summary that allows the deploy to succeed with exit code 0. | ||||||
| if (deleteErrors.length) { | ||||||
| const opts = | ||||||
| deleteErrors.length === 1 ? { original: deleteErrors[0] } : { children: deleteErrors }; | ||||||
| const msg = | ||||||
| deleteErrors.length === 1 | ||||||
| ? `Fabricator.applyDeletes encountered an unhandled exception: ${deleteErrors[0].message}` | ||||||
| : "Fabricator.applyDeletes encountered unhandled exceptions"; | ||||||
| throw new FirebaseError(msg, { | ||||||
| ...opts, | ||||||
| exit: 2, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using To maintain consistency and adhere to the standard exit codes, consider changing this to
Suggested change
References
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chatted with AI a whole lot about this and it was convinced we should do 2 since it's an unknown internal error and not a user caused error. I defer to @joehan
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I buy your logic here. We've not been super consistent about error code handling accross the codebase, but thats no reason to not try to be better here. |
||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| // Similarly to grantNewRoles, we execute role removals sequentially to avoid concurrent | ||||||
| // IAM policy update conflicts (409 Conflict / etag mismatch) on GCP. | ||||||
| for (const [codebase, codebasePlan] of Object.entries(plan)) { | ||||||
|
|
@@ -370,11 +404,11 @@ export class Fabricator { | |||||
| const ops: Array<Promise<reporter.DeployResult>> = []; | ||||||
|
|
||||||
| for (const endpoint of changes.endpointsToCreate) { | ||||||
| this.logOpStart("creating", endpoint); | ||||||
| ops.push( | ||||||
| this.wrapOperation("create", endpoint, () => | ||||||
| this.createEndpoint(endpoint, scraperV1, scraperV2), | ||||||
| ), | ||||||
| this.wrapOperation("create", endpoint, () => { | ||||||
| this.logOpStart("creating", endpoint); | ||||||
| return this.createEndpoint(endpoint, scraperV1, scraperV2); | ||||||
| }), | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -383,11 +417,11 @@ export class Fabricator { | |||||
| } | ||||||
|
|
||||||
| for (const update of changes.endpointsToUpdate) { | ||||||
| this.logOpStart("updating", update.endpoint); | ||||||
| ops.push( | ||||||
| this.wrapOperation("update", update.endpoint, () => | ||||||
| this.updateEndpoint(update, scraperV1, scraperV2), | ||||||
| ), | ||||||
| this.wrapOperation("update", update.endpoint, () => { | ||||||
| this.logOpStart("updating", update.endpoint); | ||||||
| return this.updateEndpoint(update, scraperV1, scraperV2); | ||||||
| }), | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -398,8 +432,12 @@ export class Fabricator { | |||||
| const ops: Array<Promise<reporter.DeployResult>> = []; | ||||||
|
|
||||||
| for (const endpoint of changes.endpointsToDelete) { | ||||||
| this.logOpStart("deleting", endpoint); | ||||||
| ops.push(this.wrapOperation("delete", endpoint, () => this.deleteEndpoint(endpoint))); | ||||||
| ops.push( | ||||||
| this.wrapOperation("delete", endpoint, () => { | ||||||
| this.logOpStart("deleting", endpoint); | ||||||
| return this.deleteEndpoint(endpoint); | ||||||
| }), | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| return Promise.all(ops); | ||||||
|
|
@@ -1177,7 +1215,9 @@ export class Fabricator { | |||||
| } | ||||||
|
|
||||||
| logOpStart(op: string, endpoint: backend.Endpoint): void { | ||||||
| const runtime = endpoint.runtime ? RUNTIMES[endpoint.runtime].friendly : "unknown"; | ||||||
| const runtime = endpoint.runtime | ||||||
| ? RUNTIMES[endpoint.runtime]?.friendly ?? endpoint.runtime | ||||||
| : "unknown"; | ||||||
| const platform = getHumanFriendlyPlatformName(endpoint.platform); | ||||||
| const label = helper.getFunctionLabel(endpoint); | ||||||
| utils.logLabeledBullet( | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.