Skip to content

Commit

Permalink
Fix crash when deploying zero functions. (#3520)
Browse files Browse the repository at this point in the history
Previously most code read the desired backend from
`options.config.get("functions.backend")` which was set to the
empty backend correctly. Code that depended on payload.functions.backend
crashed because payload.functions was null when the backend was
empty.

Since optins.config should be firebase.json data, this change
normalizes on payload.functions.backend and ensures that it
is never null while options.config.get('functions') is present
(i.e. when the customer has functions to deploy).
  • Loading branch information
inlined committed Jun 21, 2021
1 parent 96dd4c0 commit 6827008
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/deploy/functions/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function deploy(
}

try {
const want = options.config.get("functions.backend") as backend.Backend;
const want = payload.functions!.backend;
const uploads: Promise<void>[] = [];
if (want.cloudFunctions.some((fn) => fn.apiVersion === 1)) {
uploads.push(uploadSourceV1(context));
Expand Down
7 changes: 1 addition & 6 deletions src/deploy/functions/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function prepare(

logger.debug(`Analyzing ${runtimeDelegate.name} backend spec`);
const wantBackend = await runtimeDelegate.discoverSpec(runtimeConfig, env);
options.config.set("functions.backend", wantBackend);
payload.functions = { backend: wantBackend };
if (backend.isEmptyBackend(wantBackend)) {
return;
}
Expand Down Expand Up @@ -91,11 +91,6 @@ export async function prepare(
})
);

// Build a regionMap, and duplicate functions for each region they are being deployed to.
payload.functions = {
backend: wantBackend,
};

// Validate the function code that is being deployed.
validate.functionIdsAreValid(wantBackend.cloudFunctions);

Expand Down

0 comments on commit 6827008

Please sign in to comment.