Skip to content
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

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

Merged
merged 4 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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