Skip to content

Commit

Permalink
Fix bug where CLI would crash when customers upload an empty function…
Browse files Browse the repository at this point in the history
…s project (#3705)

* Fix bug where CLI would crash when customers upload an empty functions project

* Changelog
  • Loading branch information
inlined committed Sep 4, 2021
1 parent 98058cc commit 37f5cc7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -0,0 +1 @@
- Fixes a crash when customers deploy an empty functions project (#3705)
18 changes: 10 additions & 8 deletions src/deploy/functions/deploy.ts
Expand Up @@ -53,12 +53,12 @@ export async function deploy(
return;
}

await checkHttpIam(context, options, payload);

if (!context.functionsSourceV1 && !context.functionsSourceV2) {
return;
}

await checkHttpIam(context, options, payload);

try {
const want = payload.functions!.backend;
const uploads: Promise<void>[] = [];
Expand Down Expand Up @@ -86,12 +86,14 @@ export async function deploy(
options.config.src.functions.source,
"Error: 'functions.source' is not defined"
);
logSuccess(
clc.green.bold("functions:") +
" " +
clc.bold(options.config.src.functions.source) +
" folder uploaded successfully"
);
if (uploads.length) {
logSuccess(
clc.green.bold("functions:") +
" " +
clc.bold(options.config.src.functions.source) +
" folder uploaded successfully"
);
}
} catch (err) {
logWarning(clc.yellow("functions:") + " Upload Error: " + err.message);
throw err;
Expand Down
17 changes: 8 additions & 9 deletions src/deploy/functions/prepare.ts
Expand Up @@ -89,9 +89,6 @@ export async function prepare(
const wantBackend = await runtimeDelegate.discoverSpec(runtimeConfig, firebaseEnvs);
wantBackend.environmentVariables = { ...userEnvs, ...firebaseEnvs };
payload.functions = { backend: wantBackend };
if (backend.isEmptyBackend(wantBackend)) {
return;
}

// Note: Some of these are premium APIs that require billing to be enabled.
// We'd eventually have to add special error handling for billing APIs, but
Expand All @@ -109,12 +106,14 @@ export async function prepare(
await Promise.all(enablements);
}

logBullet(
clc.cyan.bold("functions:") +
" preparing " +
clc.bold(options.config.src.functions.source) +
" directory for uploading..."
);
if (wantBackend.cloudFunctions.length) {
logBullet(
clc.cyan.bold("functions:") +
" preparing " +
clc.bold(options.config.src.functions.source) +
" directory for uploading..."
);
}
if (wantBackend.cloudFunctions.find((fn) => fn.platform === "gcfv1")) {
context.functionsSourceV1 = await prepareFunctionsUpload(runtimeConfig, options);
}
Expand Down

0 comments on commit 37f5cc7

Please sign in to comment.