{"record":{"id":"f1dd119887521ee0","repo":"affaan-m/ECC","slug":"exit-code-with-watch-requires-watch-count-so","errorCode":null,"errorMessage":"--exit-code with --watch requires --watch-count so the process can exit","messagePattern":"--exit-code with --watch requires --watch-count so the process can exit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"scripts/loop-status.js","lineNumber":126,"sourceCode":"      options.exitCode = true;\n    } else if (arg === '--watch') {\n      options.watch = true;\n    } else if (arg === '--watch-count') {\n      options.watchCount = readPositiveInteger(readValue(args, index, arg), arg);\n      index += 1;\n    } else if (arg === '--watch-interval-seconds') {\n      options.watchIntervalSeconds = readPositiveNumber(readValue(args, index, arg), arg);\n      index += 1;\n    } else if (arg === '--write-dir') {\n      options.writeDir = readValue(args, index, arg);\n      index += 1;\n    } else {\n      throw new Error(`Unknown option: ${arg}`);\n    }\n  }\n\n  if (options.exitCode && options.watch && options.watchCount === null) {\n    throw new Error('--exit-code with --watch requires --watch-count so the process can exit');\n  }\n\n  return options;\n}\n\nfunction normalizeOptions(options = {}) {\n  return {\n    ...options,\n    bashTimeoutSeconds: options.bashTimeoutSeconds ?? DEFAULT_BASH_TIMEOUT_SECONDS,\n    exitCode: Boolean(options.exitCode),\n    limit: options.limit ?? DEFAULT_LIMIT,\n    transcriptPaths: options.transcriptPaths || [],\n    watch: Boolean(options.watch),\n    watchCount: options.watchCount ?? null,\n    wakeGraceMultiplier: options.wakeGraceMultiplier ?? DEFAULT_WAKE_GRACE_MULTIPLIER,\n    watchIntervalSeconds: options.watchIntervalSeconds ?? DEFAULT_WATCH_INTERVAL_SECONDS,\n    writeDir: options.writeDir || null,\n  };","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/loop-status.js#L108-L144","documentation":"A cross-flag validation in parseArgs: combining --exit-code (non-zero exit when loops look stuck) with --watch (continuous refresh loop) requires --watch-count so the process has a deterministic stopping point. Without a count, --watch would loop forever and --exit-code could never reliably terminate the process, so the script refuses the ambiguous combination.","triggerScenarios":"Invoking `loop-status.js --exit-code --watch` with no --watch-count. Adding --watch for live monitoring but forgetting that --exit-code needs a bounded run to make sense.","commonSituations":"CI scripts that want both an exit gate and periodic updates. Operators copying a watch example into an exit-code pipeline without the count.","solutions":["Add --watch-count N, e.g. `--exit-code --watch --watch-count 10`.","If you do not need continuous refresh, drop --watch and rely on a single-shot --exit-code run.","If you do not need an exit gate, drop --exit-code and let --watch run unbounded (still requires Ctrl-C)."],"exampleFix":"# before\nnode scripts/loop-status.js --exit-code --watch\n\n# after\nnode scripts/loop-status.js --exit-code --watch --watch-count 10","handlingStrategy":"validation","validationCode":"function validateFlagCombinations(opts) {\n  if (opts.exitCode && opts.watch && (opts.watchCount === null || opts.watchCount === undefined)) {\n    throw new Error('--exit-code with --watch requires --watch-count so the process can exit');\n  }\n}","typeGuard":null,"tryCatchPattern":"try { parseArgs(process.argv); }\ncatch (err) { if (/requires --watch-count/.test(err.message)) { console.error(err.message); printHelp(2); } else throw err; }","preventionTips":["In CI templates, always pair --exit-code --watch with a fixed --watch-count.","For one-shot exit gating, omit --watch entirely.","Document the rationale (bounded termination) next to the flag."],"tags":["cli","argument-parsing","flag-combination"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}