affaan-m/ECC · error

Invalid

Error message

Invalid ${flagName}: ${value}

What it means

parseIntegerFlag parses numeric CLI values for platform-audit (e.g. limits, page sizes). It uses Number.parseInt in base 10 and rejects the result if it is not a finite number or is negative, throwing `Invalid <flagName>: <value>`. Note parseInt is lenient about trailing garbage ('10abc' parses as 10), so the error fires mainly for non-numeric or negative input.

Solutions

  1. Provide a plain non-negative base-10 integer: `--limit 50`.
  2. Strip units/separators: use 1000 not '1,000', 30 not '30s'.
  3. If you need 'all', check whether the flag accepts 0 or a large sentinel rather than a negative number.
  4. Validate in wrappers: `[[ $LIMIT =~ ^[0-9]+$ ]] || { echo "bad limit"; exit 1; }` before invoking.

Example fix

// before
args.push('--limit', process.env.AUDIT_LIMIT); // '' -> NaN

// after
const limit = Number.parseInt(process.env.AUDIT_LIMIT ?? '', 10);
if (!Number.isFinite(limit) || limit < 0) {
  throw new Error(`AUDIT_LIMIT must be a non-negative integer, got "${process.env.AUDIT_LIMIT}"`);
}
args.push('--limit', String(limit));
Defensive patterns

Strategy: validation

Validate before calling

const isNonNegativeInt = (v) => /^\d+$/.test(String(v));
if (!isNonNegativeInt(limit)) throw new Error(`limit must be a non-negative integer, got "${limit}"`);

Type guard

const isNonNegativeInt = (v) => typeof v === 'string' && /^\d+$/.test(v) && Number.isSafeInteger(Number(v));

Try / catch

try {
  const parsed = parseArgs(process.argv);
} catch (err) {
  if (/^Invalid /.test(err.message)) {
    console.error(`${err.message} — numeric flags take plain non-negative integers (e.g. --limit 50)`);
    process.exit(2);
  }
  throw err;
}

Prevention

When it happens

Trigger: Passing a non-numeric value (`--limit ten`), a negative number (`--limit -1`), a decimal that parseInt truncates is accepted but a pure non-numeric string is not, or an empty/unset shell variable so the value is '' (NaN).

Common situations: Copy-pasting values with units ('500ms', '5k') instead of bare integers; locale-formatted numbers with thousands separators ('1,000'); misremembering flag semantics and passing a negative 'offset from end'; an env var defaulting to empty string and becoming NaN.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


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

Appendix: source

Thrown at scripts/platform-audit.js:61

    '  --allow-untracked <path>   Ignore untracked files under path; repeatable',
    '  --use-env-github-token     Keep GITHUB_TOKEN when invoking gh',
    '  --exit-code                Return 2 when the audit is not ready',
    '  --help, -h                 Show this help',
  ].join('\n'));
}

function readValue(args, index, flagName) {
  const value = args[index + 1];
  if (!value || value.startsWith('--')) {
    throw new Error(`${flagName} requires a value`);
  }
  return value;
}

function parseIntegerFlag(value, flagName) {
  const parsed = Number.parseInt(value, 10);
  if (!Number.isFinite(parsed) || parsed < 0) {
    throw new Error(`Invalid ${flagName}: ${value}`);
  }
  return parsed;
}

function parseArgs(argv) {
  const args = argv.slice(2);
  const parsed = {
    allowUntracked: [],
    exitCode: false,
    format: 'text',
    help: false,
    repos: [],
    root: path.resolve(process.cwd()),
    skipGithub: false,
    thresholds: { ...DEFAULT_THRESHOLDS },
    useEnvGithubToken: false,
    writePath: null,
  };

View on GitHub (pinned to 8321021c54)