affaan-m/ECC · error · Error

Unknown argument

Error message

Unknown argument: ${arg}

What it means

After recognized flags, parseArgs only allows a bare positional argument when the command is 'show' and no componentId has been captured yet. Any other unrecognized token reaches the else branch and throws `Unknown argument: ${arg}`, protecting users from silently ignored typos.

Solutions

  1. Fix or remove the unrecognized token — run `catalog --help` to list valid flags
  2. Move positionals: only `catalog show <componentId>` accepts a positional ID
  3. Quote arguments with spaces so they don't split into extra tokens
  4. If a flag was renamed, use the new spelling

Example fix

// before
node scripts/catalog.js list my-component
// Error: Unknown argument: my-component
// after
node scripts/catalog.js show my-component
Defensive patterns

Strategy: validation

Validate before calling

const KNOWN = ['--help','-h','--json','--family','--target'];
const bad = process.argv.slice(3).filter(a => a.startsWith('--') && !KNOWN.includes(a));
if (bad.length) { console.error(`Unknown flags: ${bad.join(' ')}`); process.exit(2); }

Try / catch

try {
  const options = parseArgs(process.argv.slice(2));
} catch (err) {
  if (err.message.startsWith('Unknown argument')) {
    console.error(`${err.message} — run 'catalog --help' for valid flags`);
    process.exit(2);
  }
  throw err;
}

Prevention

When it happens

Trigger: Typo'd flags (e.g. `--famil skill`), passing a positional to commands other than 'show' (e.g. `catalog list myid`), passing a second positional to `show`, or mis-quoted arguments splitting into stray tokens.

Common situations: Shell word-splitting introducing extra tokens; muscle-memory positionals like `catalog list component-xyz` (list takes no positional); deprecated/renamed flags from older docs.

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/36e6b4222c0f1084. Report an issue: GitHub.

Appendix: source

Thrown at scripts/catalog.js:92

      parsed.help = true;
    } else if (arg === '--json') {
      parsed.json = true;
    } else if (arg === '--family') {
      if (!args[index + 1]) {
        throw new Error('Missing value for --family');
      }
      parsed.family = normalizeFamily(args[index + 1]);
      index += 1;
    } else if (arg === '--target') {
      if (!args[index + 1]) {
        throw new Error('Missing value for --target');
      }
      parsed.target = args[index + 1];
      index += 1;
    } else if (parsed.command === 'show' && !parsed.componentId) {
      parsed.componentId = arg;
    } else {
      throw new Error(`Unknown argument: ${arg}`);
    }
  }

  return parsed;
}

function printProfiles(profiles) {
  console.log('Install profiles:\n');
  for (const profile of profiles) {
    console.log(`- ${profile.id} (${profile.moduleCount} modules)`);
    console.log(`  ${profile.description}`);
  }
}

function printComponents(components) {
  console.log('Install components:\n');
  for (const component of components) {
    console.log(`- ${component.id} [${component.family}]`);

View on GitHub (pinned to 8321021c54)