affaan-m/ECC · error · Error

Invalid ${flagName}: ${value}

Error message

Invalid ${flagName}: ${value}

What it means

The parseIntegerFlag() function in discussion-audit.js uses Number.parseInt() and validates that the result is finite and greater than zero. This is used for the --first flag (number of discussions to sample per repo). Values like 0, negative numbers, NaN (from non-numeric strings), Infinity, or floats truncated to zero by parseInt all fail.

Source

Thrown at scripts/discussion-audit.js:52

    '  --first <n>                Discussions to sample per repo (default: 100)',
    '  --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 = {
    exitCode: false,
    first: DEFAULT_DISCUSSION_FIRST,
    format: 'text',
    help: false,
    repos: [],
    useEnvGithubToken: false,
    writePath: null,
  };

  for (let index = 0; index < args.length; index += 1) {
    const arg = args[index];

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Provide a positive integer, e.g. --first 100
  2. If deriving from a variable, validate it is >= 1 before passing
  3. Omit --first to use the default (DEFAULT_DISCUSSION_FIRST)

Example fix

// before
node scripts/discussion-audit.js --first 0
node scripts/discussion-audit.js --first abc
// after
node scripts/discussion-audit.js --first 50
Defensive patterns

Strategy: validation

Validate before calling

// Validate the --first value before passing it
function isValidPositiveInteger(value) {
  const n = Number.parseInt(value, 10);
  return Number.isFinite(n) && n > 0;
}
const first = process.env.AUDIT_FIRST || '100';
if (!isValidPositiveInteger(first)) {
  console.error(`Invalid --first value: ${first}. Must be a positive integer.`);
  process.exit(1);
}

Type guard

// Type guard for a positive integer
function isPositiveInteger(value) {
  const n = Number.parseInt(value, 10);
  return Number.isFinite(n) && n > 0 && String(n) === String(value);
}

Try / catch

try {
  const options = parseArgs(process.argv);
} catch (error) {
  if (error.message.startsWith('Invalid') && error.message.includes(':')) {
    console.error(error.message);
    console.error('The --first flag requires a positive integer, e.g. --first 100');
    process.exit(2);
  }
  throw error;
}

Prevention

When it happens

Trigger: Passing --first 0 (no discussions sampled), --first -10 (negative), --first abc (non-numeric), or --first 0.5 (parseInt returns 0). Note that parseInt('3.7') returns 3, which would pass — only values that parse to zero or NaN fail.

Common situations: Scripts deriving --first from a variable or calculation that can produce 0; passing a float that truncates to 0; environment-driven configuration with an unset variable defaulting to 0.

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/039b974ad322f20a. Report an issue: GitHub.