From 7d2b1f2d860f1dcd949e71fcc5b671af33169048 Mon Sep 17 00:00:00 2001 From: Renato Monteiro <45536168+monteiro-renato@users.noreply.github.com> Date: Fri, 5 Jun 2026 14:16:36 +0200 Subject: [PATCH] fix: validate --env is not passed with an empty string --- src/cli/commands/deploy/deploy.spec.ts | 8 ++++++++ src/cli/commands/deploy/deploy.ts | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/cli/commands/deploy/deploy.spec.ts b/src/cli/commands/deploy/deploy.spec.ts index 313de36b..9d12fee5 100644 --- a/src/cli/commands/deploy/deploy.spec.ts +++ b/src/cli/commands/deploy/deploy.spec.ts @@ -307,5 +307,13 @@ describe("deploy", () => { expect(env.FUNCTION_LANGUAGE_VERSION).toBe(DEFAULT_VERSION.DotnetIsolated); expect(SUPPORTED_VERSIONS.DotnetIsolated).toContain(env.FUNCTION_LANGUAGE_VERSION); }); + + it("should print an error when --env is an empty string", async () => { + await deploy({ + outputLocation: "/test-output", + env: "", + }); + expect(logger.error).toHaveBeenNthCalledWith(1, "Invalid --env: cannot be empty. Use 'preview' or omit the flag."); + }); }); }); diff --git a/src/cli/commands/deploy/deploy.ts b/src/cli/commands/deploy/deploy.ts index f748accd..969a7c77 100644 --- a/src/cli/commands/deploy/deploy.ts +++ b/src/cli/commands/deploy/deploy.ts @@ -255,6 +255,10 @@ export async function deploy(options: SWACLIConfig) { // set the DEPLOYMENT_ENVIRONMENT env variable only when the user has provided // a deployment environment which is not "production". if (options.env?.toLowerCase() !== "production" && options.env?.toLowerCase() !== "prod") { + if (options.env !== undefined && !options.env.trim()) { + logger.error("Invalid --env: cannot be empty. Use 'preview' or omit the flag."); + return; + } deployClientEnv.DEPLOYMENT_ENVIRONMENT = options.env; }