diff --git a/src/cli/commands/deploy/deploy.spec.ts b/src/cli/commands/deploy/deploy.spec.ts index 313de36b..82a9025f 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 a named environment (e.g. 'preview') or omit the flag."); + }); }); }); diff --git a/src/cli/commands/deploy/deploy.ts b/src/cli/commands/deploy/deploy.ts index f748accd..94b1ada3 100644 --- a/src/cli/commands/deploy/deploy.ts +++ b/src/cli/commands/deploy/deploy.ts @@ -60,6 +60,12 @@ export async function deploy(options: SWACLIConfig) { } } + // make sure --env is not an empty string + if (options.env !== undefined && !options.env.trim()) { + logger.error("Invalid --env: cannot be empty. Use a named environment (e.g. 'preview') or omit the flag."); + return; + } + logger.silly(`Resolving outputLocation=${outputLocation} full path...`); let resolvedOutputLocation = path.resolve(appLocation, outputLocation as string);