affaan-m/ECC · error · Error

must be a positive integer

Error message

${flagName} must be a positive integer

What it means

scripts/loop-status.js validates numeric CLI flags through readPositiveInteger, which first parses the value with readPositiveNumber and then rejects any non-integer result. This flag is documented to accept only positive whole numbers (e.g. --watch-count 5). Passing a fractional value like 2.5 makes Number.isInteger fail and the script aborts with '<flagName> must be a positive integer'.

Solutions

  1. Pass a whole number, e.g. `--watch-count 3` instead of `--watch-count 2.5`.
  2. If the value comes from a variable, round it first: `Math.round(value)` or `Math.floor(value)` before invoking the script.
  3. Check your shell/config for accidental decimal formatting (locale decimal separators like '2,5').
  4. If you truly need fractional intervals, use a flag backed by readPositiveNumber (e.g. --watch-interval-seconds) instead of the integer-only flag.

Example fix

// before
node scripts/loop-status.js --watch --watch-count 2.5
// after
node scripts/loop-status.js --watch --watch-count 3
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(rawValue);
if (!Number.isInteger(n) || n <= 0) throw new Error(`${flag} must be a positive integer`);

Type guard

const isPositiveInt = (v) => Number.isInteger(v) && v > 0;

Try / catch

try { run(args); } catch (e) { if (String(e.message).includes('must be a positive integer')) { console.error('Fix the flag value to a whole number'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Running `node scripts/loop-status.js --watch-count 2.5`, `--watch-count 0.5`, or any decimal/NaN-producing value for a flag routed through readPositiveInteger (e.g. --watch-count) via parseArgs.

Common situations: Typing a decimal interval by mistake, copying values from docs that use seconds with fractions, or scripting with computed values that are floats due to division.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/fbe4e55d8e3fe1be. Report an issue: GitHub.

Appendix: source

Thrown at scripts/loop-status.js:59

  const value = args[index + 1];
  if (!value || value.startsWith('--')) {
    throw new Error(`${flagName} requires a value`);
  }
  return value;
}

function readPositiveNumber(value, flagName) {
  const number = Number(value);
  if (!Number.isFinite(number) || number <= 0) {
    throw new Error(`${flagName} must be a positive number`);
  }
  return number;
}

function readPositiveInteger(value, flagName) {
  const number = readPositiveNumber(value, flagName);
  if (!Number.isInteger(number)) {
    throw new Error(`${flagName} must be a positive integer`);
  }
  return number;
}

function parseArgs(argv) {
  const args = argv.slice(2);
  const options = {
    bashTimeoutSeconds: DEFAULT_BASH_TIMEOUT_SECONDS,
    exitCode: false,
    home: null,
    json: false,
    limit: DEFAULT_LIMIT,
    now: null,
    showHelp: false,
    transcriptPaths: [],
    watch: false,
    watchCount: null,
    wakeGraceMultiplier: DEFAULT_WAKE_GRACE_MULTIPLIER,

View on GitHub (pinned to 8321021c54)