Hmbown/CodeWhale · error · Error
unknown argument: ${arg}
Error message
unknown argument: ${arg} What it means
compare-deployed-facts.mjs parseArgs recognizes exactly --require-current (boolean), --base-url <url>, --expected-revision <sha>, --attempts <n>, and --retry-delay-ms <ms>; anything else throws `unknown argument: ${arg}`. Note --attempts defaults to 6 when --require-current is set, otherwise 1.
Source
Thrown at web/scripts/compare-deployed-facts.mjs:32
expectedRevision: process.env.CODEWHALE_SOURCE_REVISION || process.env.GITHUB_SHA || null,
requireCurrent: false,
attempts: null,
retryDelayMs: 3_000,
};
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];
if (arg === "--require-current") {
out.requireCurrent = true;
} else if (arg === "--base-url") {
out.baseUrl = argv[++index];
} else if (arg === "--expected-revision") {
out.expectedRevision = argv[++index];
} else if (arg === "--attempts") {
out.attempts = Number(argv[++index]);
} else if (arg === "--retry-delay-ms") {
out.retryDelayMs = Number(argv[++index]);
} else {
throw new Error(`unknown argument: ${arg}`);
}
}
out.attempts ??= out.requireCurrent ? 6 : 1;
return out;
}
function localRevision() {
try {
return execFileSync("git", ["rev-parse", "HEAD"], {
cwd: REPO_ROOT,
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
}).trim();
} catch {
return null;
}
}
View on GitHub (pinned to 8880682c63)
Solutions
- Rerun with only the five documented flags, spelled exactly as parsed
- Ensure every value flag (--base-url, --expected-revision, --attempts, --retry-delay-ms) is followed by its value — the parser does not validate missing values itself
- When adding a flag, extend the else-if chain and keep the final else throw intact
Example fix
# before node scripts/compare-deployed-facts.mjs --baseurl https://example.com # after node scripts/compare-deployed-facts.mjs --base-url https://example.com
Defensive patterns
Strategy: validation
Validate before calling
const VALUE_FLAGS = new Set(['--base-url', '--expected-revision', '--attempts', '--retry-delay-ms']);
const argv = process.argv.slice(2);
for (let i = 0; i < argv.length; i += 1) {
const a = argv[i];
if (VALUE_FLAGS.has(a)) { i += 1; continue; }
if (a !== '--require-current') {
console.error(`unknown argument: ${a} — see script header for usage`);
process.exit(2);
}
} Try / catch
try {
parseArgs(process.argv.slice(2));
} catch (error) {
if (/^unknown argument:/.test(error.message)) { process.exit(2); }
throw error;
} Prevention
- Read the parseArgs chain at the top of the script before adding flags
- Always pair value flags with their value on the same command line
When it happens
Trigger: Passing unsupported or misspelled flags (--baseurl, --verbose), stray positionals, or a value flag whose missing value makes the next token be parsed as a flag and rejected.
Common situations: Adapting an ad-hoc curl check into this script; flags copied from another web/scripts tool; wrapper scripts appending extra arguments.
Related errors
- unknown argument: ${arg}
- unknown argument: ${arg}
- --days must be an integer from 1 through 90
- invalid --base-url: ${args.baseUrl}
- --base-url must use http or https
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/ddc18233f6effab8.
Report an issue: GitHub.