{"record":{"id":"fbe4e55d8e3fe1be","repo":"affaan-m/ECC","slug":"flagname-must-be-a-positive-integer","errorCode":null,"errorMessage":"${flagName} must be a positive integer","messagePattern":"(.+?) must be a positive integer","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/loop-status.js","lineNumber":59,"sourceCode":"  const value = args[index + 1];\n  if (!value || value.startsWith('--')) {\n    throw new Error(`${flagName} requires a value`);\n  }\n  return value;\n}\n\nfunction readPositiveNumber(value, flagName) {\n  const number = Number(value);\n  if (!Number.isFinite(number) || number <= 0) {\n    throw new Error(`${flagName} must be a positive number`);\n  }\n  return number;\n}\n\nfunction readPositiveInteger(value, flagName) {\n  const number = readPositiveNumber(value, flagName);\n  if (!Number.isInteger(number)) {\n    throw new Error(`${flagName} must be a positive integer`);\n  }\n  return number;\n}\n\nfunction parseArgs(argv) {\n  const args = argv.slice(2);\n  const options = {\n    bashTimeoutSeconds: DEFAULT_BASH_TIMEOUT_SECONDS,\n    exitCode: false,\n    home: null,\n    json: false,\n    limit: DEFAULT_LIMIT,\n    now: null,\n    showHelp: false,\n    transcriptPaths: [],\n    watch: false,\n    watchCount: null,\n    wakeGraceMultiplier: DEFAULT_WAKE_GRACE_MULTIPLIER,","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/loop-status.js#L41-L77","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a whole number, e.g. `--watch-count 3` instead of `--watch-count 2.5`.","If the value comes from a variable, round it first: `Math.round(value)` or `Math.floor(value)` before invoking the script.","Check your shell/config for accidental decimal formatting (locale decimal separators like '2,5').","If you truly need fractional intervals, use a flag backed by readPositiveNumber (e.g. --watch-interval-seconds) instead of the integer-only flag."],"exampleFix":"// before\nnode scripts/loop-status.js --watch --watch-count 2.5\n// after\nnode scripts/loop-status.js --watch --watch-count 3","handlingStrategy":"validation","validationCode":"const n = Number(rawValue);\nif (!Number.isInteger(n) || n <= 0) throw new Error(`${flag} must be a positive integer`);","typeGuard":"const isPositiveInt = (v) => Number.isInteger(v) && v > 0;","tryCatchPattern":"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; }","preventionTips":["Round computed values before passing them as flag arguments","Avoid locale-formatted numbers on the command line","Validate numeric flags in wrapper scripts before exec"],"tags":["cli","validation","argument-parsing"],"backgroundTag":"invalid-flag-value","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}