Skip to content

Commit 7d2b1f2

Browse files
fix: validate --env is not passed with an empty string
1 parent 2400910 commit 7d2b1f2

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/cli/commands/deploy/deploy.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,13 @@ describe("deploy", () => {
307307
expect(env.FUNCTION_LANGUAGE_VERSION).toBe(DEFAULT_VERSION.DotnetIsolated);
308308
expect(SUPPORTED_VERSIONS.DotnetIsolated).toContain(env.FUNCTION_LANGUAGE_VERSION);
309309
});
310+
311+
it("should print an error when --env is an empty string", async () => {
312+
await deploy({
313+
outputLocation: "/test-output",
314+
env: "",
315+
});
316+
expect(logger.error).toHaveBeenNthCalledWith(1, "Invalid --env: cannot be empty. Use 'preview' or omit the flag.");
317+
});
310318
});
311319
});

src/cli/commands/deploy/deploy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ export async function deploy(options: SWACLIConfig) {
255255
// set the DEPLOYMENT_ENVIRONMENT env variable only when the user has provided
256256
// a deployment environment which is not "production".
257257
if (options.env?.toLowerCase() !== "production" && options.env?.toLowerCase() !== "prod") {
258+
if (options.env !== undefined && !options.env.trim()) {
259+
logger.error("Invalid --env: cannot be empty. Use 'preview' or omit the flag.");
260+
return;
261+
}
258262
deployClientEnv.DEPLOYMENT_ENVIRONMENT = options.env;
259263
}
260264

0 commit comments

Comments
 (0)