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; }