From 37f5cc785281d13fe1da26f9be24412bffab40f7 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Fri, 3 Sep 2021 17:10:38 -0700 Subject: [PATCH] Fix bug where CLI would crash when customers upload an empty functions project (#3705) * Fix bug where CLI would crash when customers upload an empty functions project * Changelog --- CHANGELOG.md | 1 + src/deploy/functions/deploy.ts | 18 ++++++++++-------- src/deploy/functions/prepare.ts | 17 ++++++++--------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..ad30db661f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Fixes a crash when customers deploy an empty functions project (#3705) diff --git a/src/deploy/functions/deploy.ts b/src/deploy/functions/deploy.ts index 5029a06a7a5..8d4c7bd1265 100644 --- a/src/deploy/functions/deploy.ts +++ b/src/deploy/functions/deploy.ts @@ -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[] = []; @@ -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; diff --git a/src/deploy/functions/prepare.ts b/src/deploy/functions/prepare.ts index b69bb9411c4..76f72396396 100644 --- a/src/deploy/functions/prepare.ts +++ b/src/deploy/functions/prepare.ts @@ -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 @@ -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); }