santifer/career-ops · error · Error

Missing value for ${arg}

Error message

Missing value for ${arg}

What it means

Thrown by `parseArgs` in application-answers.mjs when a `--flag` is the last token or is immediately followed by another `--flag`. Each option requires a value; CLI conventions treat a following `--` as a missing operand rather than a value, so the parser refuses to silently consume a flag name as data.

Source

Thrown at application-answers.mjs:168

  const start = heading.index;
  const afterHeading = start + heading[0].length;
  const nextHeading = /^## .+$/m.exec(report.slice(afterHeading));
  const end = nextHeading ? afterHeading + nextHeading.index : report.length;
  const before = report.slice(0, start).trimEnd();
  const after = report.slice(end).trimStart();

  return [before, section, after].filter(Boolean).join('\n\n') + '\n';
}

function parseArgs(argv) {
  const args = {};
  for (let i = 0; i < argv.length; i += 1) {
    const arg = argv[i];
    if (arg === '--help' || arg === '-h') args.help = true;
    else if (arg.startsWith('--')) {
      const value = argv[i + 1];
      if (!value || value.startsWith('--')) {
        throw new Error(`Missing value for ${arg}`);
      }
      args[arg.slice(2)] = value;
      i += 1;
    }
  }
  return args;
}

function usage() {
  return [
    'Usage: node application-answers.mjs --report <report.md> --input <answers.json> [--state filled|submitted] [--date YYYY-MM-DD]',
    '',
    'The input JSON may contain: freeText, selections, fieldValues, files, date, state.',
  ].join('\n');
}

async function main() {
  let args;

View on GitHub (pinned to 9b17a8ac97)

Solutions

  1. Provide a value for every `--flag`: `--report <path> --input <path> [--state <s>] [--date <d>]`.
  2. If you intended an empty value, pass an explicit empty string (`--report ""`) — though here that likely fails downstream; prefer omitting the flag.
  3. Quote values containing spaces and check the shell didn't strip them.
  4. Run with `--help` to see the documented argument order and required flags.
  5. Validate argv length / shape in a wrapper before invoking if generating the command programmatically.

Example fix

// before
node application-answers.mjs --report --input answers.json
// after
node application-answers.mjs --report reports/042-acme.md --input answers.json
Defensive patterns

Strategy: validation

Validate before calling

function ensureValues(argv) {
  for (let i = 0; i < argv.length; i++) {
    if (argv[i].startsWith('--')) {
      const v = argv[i + 1];
      if (!v || v.startsWith('--')) throw new Error(`Missing value for ${argv[i]}`);
    }
  }
}

Try / catch

try { runCli(argv); }
catch (e) {
  if (/Missing value for/.test(e.message)) {
    printUsage(); // show the documented arg order
  } else throw e;
}

Prevention

When it happens

Trigger: Running `node application-answers.mjs --report --input a.json` (no value after `--report`); ending with `--input` as the last arg; `--state` followed by `--date`; any `--key` with no positional value.

Common situations: User forgets the value; shell quoting eats an empty string (`--report ""` is technically allowed but a missing following token is not); copy-paste from docs that truncated a line; argument reordering that left a flag dangling.

Related errors


AI-assisted analysis of santifer/career-ops@9b17a8ac97 (2026-08-13). Data as JSON: /api/errors/a51bb0410ce571cb. Report an issue: GitHub.