santifer/career-ops · error · Error

--limit must be an integer from 1 to 100

Error message

--limit must be an integer from 1 to 100

What it means

parseArgs validates `--limit` after the flag loop: it must be an integer (Number.isInteger), strictly positive, and at most 100. `--limit` is converted with Number(), so non-numeric text becomes NaN and fails the check, producing this error.

Solutions

  1. Pass an integer between 1 and 100, e.g. `--limit 50`.
  2. Clamp or floor the value in the calling script before forwarding it.
  3. Validate the source value (env var, config) before passing it as `--limit`.
  4. Ensure `--limit` is not the final bare flag without a value.

Example fix

// before
node company-funded.mjs --limit 500

// after
node company-funded.mjs --limit 100
Defensive patterns

Strategy: validation

Validate before calling

function validLimit(n) {
  const v = Number(n);
  return Number.isInteger(v) && v > 0 && v <= 100 ? v : null;
}
// pre-check: if (validLimit(rawLimit) === null) fail fast before spawning the script

Type guard

const isBoundedInt = (v, max) => Number.isInteger(v) && v > 0 && v <= max;

Try / catch

try {
  run(['--limit', String(limit)]);
} catch (e) {
  if (e.message.includes('--limit must be')) {
    console.warn('Clamping limit to 100 and retrying');
    run(['--limit', '100']);
  } else throw e;
}

Prevention

When it happens

Trigger: `node company-funded.mjs --limit abc` (NaN), `--limit 0`, `--limit -5`, `--limit 500` (>100), `--limit 2.5` (not an integer), or `--limit` as the last argument (Number('') → NaN).

Common situations: Pasting a float or locale-formatted number; assuming the limit is unbounded; scripts parameterizing the limit from an unvalidated env var or CI input; forgetting the value after the flag.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16). Data as JSON: /api/errors/0dce3b99ac53c073. Report an issue: GitHub.

Appendix: source

Thrown at company-funded.mjs:127

    dryRun: false,
    json: false,
    selfTest: false,
    help: false,
  };
  for (let i = 0; i < argv.length; i++) {
    const arg = argv[i];
    if (arg === '--dry-run') opts.dryRun = true;
    else if (arg === '--json') opts.json = true;
    else if (arg === '--self-test') opts.selfTest = true;
    else if (arg === '--help' || arg === '-h') opts.help = true;
    else if (arg === '--limit') opts.limit = Number(argv[++i] || '');
    else if (arg === '--months') opts.months = Number(argv[++i] || '');
    else if (arg === '--sort') opts.sort = String(argv[++i] || '').trim().toLowerCase();
    else if (arg === '--sources') opts.sources = parseSources(argv[++i] || '');
    else throw new Error(`unknown option: ${arg}`);
  }
  if (!Number.isInteger(opts.limit) || opts.limit <= 0 || opts.limit > 100) {
    throw new Error('--limit must be an integer from 1 to 100');
  }
  if (!Number.isInteger(opts.months) || opts.months <= 0 || opts.months > 120) {
    throw new Error('--months must be an integer from 1 to 120');
  }
  if (!['date', 'score'].includes(opts.sort)) {
    throw new Error('--sort must be date or score');
  }
  return opts;
}

function parseSources(value) {
  const out = String(value || '')
    .split(',')
    .map((s) => normalizeSourceName(s.trim()))
    .filter(Boolean);
  const unique = [...new Set(out)];
  const allowed = new Set(['techcrunch', 'prnewswire', 'guardian', 'hn']);
  for (const source of unique) {

View on GitHub (pinned to aac998c7ed)