affaan-m/ECC · error · Error
Unknown argument
Error message
Unknown argument: ${arg} What it means
The CLI argument parser in scripts/operator-readiness-dashboard.js rejects any command-line flag it does not recognize. parseArgs whitelists known flags (--format, --json, --markdown, --write, --exit-code, --allow-untracked, etc.) and throws this error for anything else, so typos or flags borrowed from other tools fail fast at startup.
Solutions
- Read the error message: it names the exact unrecognized argument; fix the typo or remove the flag.
- Run `node scripts/operator-readiness-dashboard.js --help` (or read the top of parseArgs) to list supported flags.
- Use the documented shorthand flags instead: `--json`, `--markdown`, `--format <fmt>`, `--write <path>`, `--exit-code`.
- If the flag is genuinely needed, add an explicit parsing branch for it in parseArgs before the throw.
Example fix
// before node scripts/operator-readiness-dashboard.js --format=jason // after node scripts/operator-readiness-dashboard.js --format=json
Defensive patterns
Strategy: validation
Validate before calling
const ALLOWED = ['--format','--json','--markdown','--write','--exit-code','--allow-untracked'];
const unknown = args.filter(a => a.startsWith('--') && !ALLOWED.some(k => a === k || a.startsWith(k + '=')));
if (unknown.length) { console.error('Unknown flags:', unknown.join(', ')); process.exit(2); } Type guard
function isKnownFlag(arg, allowed) { return typeof arg === 'string' && allowed.includes(arg); } Try / catch
try {
const parsed = parseArgs(process.argv.slice(2));
await main(parsed);
} catch (err) {
if (err.message.startsWith('Unknown argument:')) {
console.error(`${err.message}\nRun with --help to see supported flags.`);
process.exit(2);
}
throw err;
} Prevention
- Wrap script invocations in npm scripts or aliases so flags are defined once
- Copy flags from the script's help/README rather than memory
- Add a shellcheck'd wrapper that validates flags before calling the script
- When adding flags, update parseArgs and docs together
When it happens
Trigger: Running the dashboard script with a misspelled or unsupported flag, e.g. `node scripts/operator-readiness-dashboard.js --formt json`, an unimplemented flag like `--verbose`, or a positional argument the parser does not skip, all reach the `throw new Error(\`Unknown argument: ${arg}\`)` line.
Common situations: Typo in a flag from memory or documentation; copying flags from another ECC script (e.g. passing `--out` instead of `--write`); shell scripts built before a flag was renamed; quoting mistakes that turn a value into a standalone token (e.g. `--format json extra`).
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- must be a positive integer
- Invalid
- Unknown argument
- all overlays must be readable local files
- all takes must be readable local files
AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16).
Data as JSON: /api/errors/6b4946d14c78cee7.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/operator-readiness-dashboard.js:214
}
if (arg === '--generated-at') {
parsed.generatedAt = readValue(args, index, arg);
index += 1;
continue;
}
if (arg.startsWith('--generated-at=')) {
parsed.generatedAt = arg.slice('--generated-at='.length);
continue;
}
if (arg === '--exit-code') {
parsed.exitCode = true;
continue;
}
throw new Error(`Unknown argument: ${arg}`);
}
if (!['text', 'json', 'markdown'].includes(parsed.format)) {
throw new Error(`Invalid format: ${parsed.format}. Use text, json, or markdown.`);
}
if (parsed.writePath && parsed.format === 'text') {
throw new Error('--write requires --json, --markdown, or --format json|markdown');
}
parsed.allowUntracked = parsed.allowUntracked.map(normalizeRelativePrefix).filter(Boolean);
return parsed;
}
function readText(rootDir, relativePath) {
try {
return fs.readFileSync(path.join(rootDir, relativePath), 'utf8');View on GitHub (pinned to 8321021c54)