affaan-m/ECC · error · Error

${flagName} requires a value

Error message

${flagName} requires a value

What it means

The readValue() helper in discussion-audit.js is used by --format, --write, --repo, and --first flags. It checks that argv[index + 1] is truthy and does not start with '--'. If the next token is undefined (flag is last) or looks like another flag (starts with '--'), it throws with the flag name. This prevents silently consuming one flag's name as another flag's value.

Source

Thrown at scripts/discussion-audit.js:44

    '',
    'Options:',
    '  --format <text|json|markdown>',
    '                             Output format (default: text)',
    '  --json                     Alias for --format json',
    '  --markdown                 Alias for --format markdown',
    '  --write <path>             Write json or markdown output to a file',
    '  --repo <owner/repo>        GitHub repo to inspect; repeatable',
    '  --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',

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Provide a concrete value immediately after each flag, e.g. --format json --write report.md
  2. If building commands dynamically, check that the value variable is truthy and does not start with '--' before appending the flag
  3. Use the --flag=value syntax (e.g. --format=json) which avoids the two-token ambiguity entirely

Example fix

// before
node scripts/discussion-audit.js --write --format json
// after
node scripts/discussion-audit.js --write report.json --format json
// or
node scripts/discussion-audit.js --write=report.json --format=json
Defensive patterns

Strategy: validation

Validate before calling

// Verify all value-expecting flags have companion values
const VALUE_FLAGS = new Set(['--format', '--write', '--repo', '--first']);
const argv = process.argv.slice(2);
for (let i = 0; i < argv.length; i++) {
  if (VALUE_FLAGS.has(argv[i])) {
    if (!argv[i + 1] || argv[i + 1].startsWith('--')) {
      console.error(`${argv[i]} requires a value`);
      process.exit(1);
    }
  }
}
// Alternatively, use --flag=value syntax to avoid the issue entirely

Try / catch

try {
  const options = parseArgs(process.argv);
} catch (error) {
  if (error.message.includes('requires a value')) {
    console.error(error.message);
    console.error('Tip: use --flag=value syntax to avoid ambiguity, e.g. --format=json');
    usage();
    process.exit(2);
  }
  throw error;
}

Prevention

When it happens

Trigger: Passing --write as the last argument; passing --format immediately followed by --json; passing --repo followed by --first; or any flag-value pair where the value is missing or is another flag.

Common situations: CI workflows that conditionally append flags but skip values when variables are empty; copy-paste errors; dynamic argument building that drops values.

Related errors


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