affaan-m/ECC · error · Error

--timeout-ms must be a positive number

Error message

--timeout-ms must be a positive number

What it means

`parseArgs` in supply-chain-advisory-sources.js reads `--timeout-ms <value>`, converts it via `Number(...)`, and validates with `!Number.isFinite(options.timeoutMs) || options.timeoutMs <= 0`. If the value is non-numeric, NaN, Infinity, zero, or negative, it throws `--timeout-ms must be a positive number`. This guards the HTTP fetch timeout used when refreshing advisory sources.

Source

Thrown at scripts/ci/supply-chain-advisory-sources.js:387

function parseArgs(argv) {
  const options = {};
  for (let i = 0; i < argv.length; i += 1) {
    const arg = argv[i];
    if (arg === '--help' || arg === '-h') {
      options.help = true;
    } else if (arg === '--json') {
      options.json = true;
    } else if (arg === '--refresh') {
      options.refresh = true;
    } else if (arg === '--strict-refresh') {
      options.strictRefresh = true;
      options.refresh = true;
    } else if (arg === '--generated-at') {
      options.generatedAt = argv[++i];
    } else if (arg === '--timeout-ms') {
      options.timeoutMs = Number(argv[++i]);
      if (!Number.isFinite(options.timeoutMs) || options.timeoutMs <= 0) {
        throw new Error('--timeout-ms must be a positive number');
      }
    } else if (arg === '--write') {
      options.writePath = argv[++i];
      if (!options.writePath) throw new Error('--write requires a path');
    } else {
      throw new Error(`Unknown argument: ${arg}`);
    }
  }
  return options;
}

function printHelp() {
  console.log(`Usage: node scripts/ci/supply-chain-advisory-sources.js [options]

Build the active supply-chain advisory source report used by the scheduled
watch workflow and Linear ITO-57 status updates.

Options:

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Pass a positive integer in milliseconds, space-separated: `--timeout-ms 30000`.
  2. Do not use `=` syntax — this parser consumes the next argv element, so `--timeout-ms=30000` is parsed as NaN.
  3. If the value comes from an env var, default it when unset: `--timeout-ms ${TIMEOUT_MS:-30000}`.
  4. Confirm the flag is not the last token on the command line (it needs a following value).

Example fix

// before — '=' syntax (parser reads next arg as NaN) and zero value
node scripts/ci/supply-chain-advisory-sources.js --timeout-ms=30000
node scripts/ci/supply-chain-advisory-sources.js --timeout-ms 0
// -> --timeout-ms must be a positive number

// after — space-separated positive integer
node scripts/ci/supply-chain-advisory-sources.js --timeout-ms 30000
Defensive patterns

Strategy: validation

Validate before calling

function parseTimeout(argv) {
  const i = argv.indexOf('--timeout-ms');
  if (i === -1) return null;
  const raw = argv[i + 1];
  if (raw === undefined) throw new Error('--timeout-ms requires a value');
  const n = Number(raw);
  if (!Number.isFinite(n) || n <= 0) {
    throw new Error(`--timeout-ms must be a positive number, got: ${raw}`);
  }
  return n;
}

Type guard

function isPositiveMillis(raw) {
  const n = Number(raw);
  return Number.isFinite(n) && n > 0;
}

Try / catch

try {
  parseArgs(argv);
} catch (error) {
  if (/--timeout-ms must be a positive number/i.test(error.message)) {
    console.error('Pass a positive integer, space-separated: --timeout-ms 30000');
    console.error('Do not use = syntax; do not pass 0, negative, or non-numeric values.');
  }
  throw error;
}

Prevention

When it happens

Trigger: Triggered by `--timeout-ms 0`, `--timeout-ms -5`, `--timeout-ms abc`, `--timeout-ms Infinity`, or omitting the value entirely (`--timeout-ms` as the last arg yields `Number(undefined)` = NaN). Also fires for `--timeout-ms` with an empty-string value (Number("") = 0).

Common situations: A CI workflow passes `--timeout-ms` without a value (trailing flag). A script interpolates an empty/unset env var. A user types `--timeout-ms=5000` (the parser expects a space-separated value, so `=5000` is read as NaN). A negative or zero value is configured to mean 'no timeout'.

Understand the failure class

Related errors


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