{"record":{"id":"d942667b33cec635","repo":"affaan-m/ECC","slug":"flagname-must-be-a-positive-number","errorCode":null,"errorMessage":"${flagName} must be a positive number","messagePattern":"(.+?) must be a positive number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"scripts/loop-status.js","lineNumber":51,"sourceCode":"    '',\n    'Examples:',\n    '  node scripts/loop-status.js --json',\n    '  node scripts/loop-status.js --transcript ~/.claude/projects/-repo/session.jsonl'\n  ].join('\\n'));\n}\n\nfunction readValue(args, index, flagName) {\n  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,","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/loop-status.js#L33-L69","documentation":"readPositiveNumber parses a numeric flag value and requires Number(value) to be finite and strictly greater than zero; anything else throws. It deliberately accepts non-integers (e.g. 1.5), so it is used for flags that legitimately allow fractions. Affects --bash-timeout-seconds, --wake-grace-multiplier, --watch-interval-seconds.","triggerScenarios":"Passing zero, a negative number, NaN/Infinity, or non-numeric text to one of the floating-point-allowed flags. Examples: `--watch-interval-seconds 0`, `--wake-grace-multiplier -1`, `--bash-timeout-seconds fast`.","commonSituations":"Misunderstanding units (passing 0 thinking it means 'no timeout'). A shell variable expanding to empty, which Number('')===0 fails the >0 check. Using an integer-only mindset for a flag that does accept decimals but still must be positive.","solutions":["Pass a positive number, e.g. `--watch-interval-seconds 2.5`.","If you need an integer-only flag, use --limit or --watch-count instead (those use readPositiveInteger).","Guard shell variables: `--watch-interval-seconds \"${INTERVAL:-5}\"`.","Remove the flag to accept the documented default instead of forcing 0."],"exampleFix":"# before\nnode scripts/loop-status.js --watch --watch-interval-seconds 0\n\n# after\nnode scripts/loop-status.js --watch --watch-interval-seconds 2","handlingStrategy":"validation","validationCode":"// Validate that numeric flags are finite and > 0 before invoking.\nfunction isPositiveNumber(v) { const n = Number(v); return Number.isFinite(n) && n > 0; }\nfunction validatePositiveNumbers(flagMap) {\n  for (const [flag, raw] of Object.entries(flagMap)) {\n    if (raw !== undefined && !isPositiveNumber(raw)) {\n      throw new Error(`${flag} must be a positive number`);\n    }\n  }\n}","typeGuard":"/** @returns {n is number} */\nfunction isPositiveNumberGuard(n) { return typeof n === 'number' && Number.isFinite(n) && n > 0; }","tryCatchPattern":"try { parseArgs(process.argv); }\ncatch (err) { if (/must be a positive number/.test(err.message)) { console.error(err.message); printHelp(2); } else throw err; }","preventionTips":["Use integer-only flags (--limit/--watch-count) when fractions make no sense.","Guard shell variables so they are never empty: `--watch-interval-seconds \"${I:-2}\"`.","Document units (seconds, multiplier) next to each numeric flag."],"tags":["cli","argument-parsing","numeric-validation"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}