Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions nixos/services/id-mail/worker/deploy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ const PLACEHOLDER = "{code}";
const args = process.argv.slice(2);
const unknownArgs = args.filter((arg) => arg !== "--dry-run");
if (args.length > 1 || unknownArgs.length > 0) {
const offenders = unknownArgs.length > 0 ? unknownArgs : args;
console.error(`unrecognized argument(s): ${offenders.join(" ")}\nusage: deploy.mjs [--dry-run]`);
// unknownArgs empty on this branch means every arg was --dry-run, so a
// length failure is a duplicate, not an unrecognized argument (#7855).
const message =
unknownArgs.length > 0
? `unrecognized argument(s): ${unknownArgs.join(" ")}`
: `duplicate argument(s): ${[...new Set(args)].join(" ")}`;
console.error(`${message}\nusage: deploy.mjs [--dry-run]`);
process.exit(2);
}
const dryRun = args.includes("--dry-run");
Expand Down
28 changes: 28 additions & 0 deletions nixos/services/id-mail/worker/deploy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ test("--bogus-flag aborts with a usage error before any external call", async ()
assert.equal(readFileSync(sb.log, "utf8"), "", "no bws/wrangler call may be logged");
});

test("a stray positional aborts with a usage error before any external call (#7855)", async () => {
const sb = makeSandbox();
const result = await runDeploy(sb, ["extra"]);
assert.equal(result.code, 2, result.stderr);
assert.match(result.stderr, /unrecognized argument\(s\): extra/);
assert.match(result.stderr, /usage: deploy\.mjs \[--dry-run\]/);
assert.equal(readFileSync(sb.log, "utf8"), "", "no bws/wrangler call may be logged");
});

test("duplicate --dry-run is named as a duplicate, not unrecognized (#7855)", async () => {
const sb = makeSandbox();
const result = await runDeploy(sb, ["--dry-run", "--dry-run"]);
assert.equal(result.code, 2, result.stderr);
assert.match(result.stderr, /duplicate argument\(s\): --dry-run/);
assert.doesNotMatch(result.stderr, /unrecognized argument/);
assert.match(result.stderr, /usage: deploy\.mjs \[--dry-run\]/);
assert.equal(readFileSync(sb.log, "utf8"), "", "no bws/wrangler call may be logged");
});

test("--dry-run with a bogus flag aborts with a usage error before any external call (#7855)", async () => {
const sb = makeSandbox();
const result = await runDeploy(sb, ["--dry-run", "--bogus-flag"]);
assert.equal(result.code, 2, result.stderr);
assert.match(result.stderr, /unrecognized argument\(s\): --bogus-flag/);
assert.match(result.stderr, /usage: deploy\.mjs \[--dry-run\]/);
assert.equal(readFileSync(sb.log, "utf8"), "", "no bws/wrangler call may be logged");
});

test("null and non-object config entries are validation errors, not TypeErrors (#6947)", async () => {
const cases = [
["null", /config must be a JSON object/],
Expand Down
Loading