affaan-m/ECC · error · Error

Unknown argument

Error message

Unknown argument

What it means

welcome.js parseArgs implements an allowlist parser: only --action and --version are recognized. Any other argument (including unknown flags, stray positionals, or mistyped variants) hits the final else branch and throws 'Unknown argument'.

Solutions

  1. Remove the unrecognized argument from the command
  2. Check spelling — the parser is exact-match, no abbreviations or aliases
  3. Consult the script header/help to see the only supported flags: --action and --version
  4. If you intended a different script's flag set, run the correct script

Example fix

// before
node scripts/welcome.js --action install --json
// after
node scripts/welcome.js --action install
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED = new Set(['--action', '--version']);
const unknown = process.argv.slice(2).filter(a => a.startsWith('--') && !ALLOWED.has(a));
if (unknown.length > 0) throw new Error(`Unknown argument(s): ${unknown.join(', ')}`);

Type guard

function isKnownFlag(arg) {
  return arg === '--action' || arg === '--version';
}

Try / catch

try {
  parseArgs(process.argv.slice(2));
} catch (err) {
  if (err.message === 'Unknown argument') {
    console.error('Only --action and --version are supported. Check spelling and script choice.');
    process.exit(2);
  }
  throw err;
}

Prevention

When it happens

Trigger: Passing any token that is not exactly `--action` or `--version`, e.g. `node scripts/welcome.js --verbose`, `--acton install` (typo), or an unexpected positional word.

Common situations: Typos in flag names; flags copied from other ECC scripts (like --target or --json used here by mistake); shell expansion adding unexpected tokens; assuming shared flag conventions across scripts.

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


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/99873232291a8853. Report an issue: GitHub.

Appendix: source

Thrown at scripts/welcome.js:39

  for (let index = 0; index < argv.length; index += 1) {
    const argument = argv[index];
    if (argument === '--action') {
      const value = argv[index + 1];
      if (!value || value.startsWith('--')) {
        throw new Error('Missing value for --action');
      }
      action = value;
      index += 1;
    } else if (argument === '--version') {
      const value = argv[index + 1];
      if (!value || value.startsWith('--')) {
        throw new Error('Missing value for --version');
      }
      version = value;
      index += 1;
    } else {
      throw new Error('Unknown argument');
    }
  }

  if (!VALID_ACTIONS.has(action)) {
    throw new Error('Invalid --action value');
  }
  if (version !== undefined && !ECC_VERSION_PATTERN.test(version)) {
    throw new Error('Invalid --version value');
  }
  return { action, version };
}

function main(argv = process.argv.slice(2)) {
  try {
    const { action, version } = parseArgs(argv);
    const color = process.env.NO_COLOR === undefined
      && process.env.TERM !== 'dumb'
      && Boolean(process.stdout.isTTY);

View on GitHub (pinned to 8321021c54)