affaan-m/ECC · error · Error

--exit-code with --watch requires --watch-count so the…

Error message

--exit-code with --watch requires --watch-count so the process can exit

What it means

scripts/loop-status.js has an explicit combination guard in parseArgs: using --exit-code together with --watch only makes sense if --watch-count is also given, otherwise a watched loop would never terminate and the process could never exit with the requested code. When --exit-code and --watch are set but --watch-count is null, the parser throws this error before doing any work.

Solutions

  1. Add an explicit count: `node scripts/loop-status.js --watch --exit-code 1 --watch-count 10`.
  2. If you do not need a bounded watch, drop --exit-code (or drop --watch) so the guard no longer applies.
  3. In CI, compute the count from your retry policy and pass it explicitly.
  4. Wrap the invocation in a script that validates the flag combination before launching.

Example fix

// before
node scripts/loop-status.js --watch --exit-code 1
// after
node scripts/loop-status.js --watch --exit-code 1 --watch-count 10
Defensive patterns

Strategy: validation

Validate before calling

const has = (f) => args.includes(f);
if (has('--exit-code') && has('--watch') && !has('--watch-count')) {
  throw new Error('--exit-code with --watch requires --watch-count');
}

Try / catch

try { run(args); } catch (e) { if (e.message.includes('--watch-count')) { console.error('Add --watch-count N when combining --watch and --exit-code'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Running `node scripts/loop-status.js --watch --exit-code 1` without `--watch-count N`.

Common situations: CI jobs that want a non-zero exit on status failure but forget the iteration cap; combining flags copied from two different example commands.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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

Appendix: source

Thrown at scripts/loop-status.js:126

      options.exitCode = true;
    } else if (arg === '--watch') {
      options.watch = true;
    } else if (arg === '--watch-count') {
      options.watchCount = readPositiveInteger(readValue(args, index, arg), arg);
      index += 1;
    } else if (arg === '--watch-interval-seconds') {
      options.watchIntervalSeconds = readPositiveNumber(readValue(args, index, arg), arg);
      index += 1;
    } else if (arg === '--write-dir') {
      options.writeDir = readValue(args, index, arg);
      index += 1;
    } else {
      throw new Error(`Unknown option: ${arg}`);
    }
  }

  if (options.exitCode && options.watch && options.watchCount === null) {
    throw new Error('--exit-code with --watch requires --watch-count so the process can exit');
  }

  return options;
}

function normalizeOptions(options = {}) {
  return {
    ...options,
    bashTimeoutSeconds: options.bashTimeoutSeconds ?? DEFAULT_BASH_TIMEOUT_SECONDS,
    exitCode: Boolean(options.exitCode),
    limit: options.limit ?? DEFAULT_LIMIT,
    transcriptPaths: options.transcriptPaths || [],
    watch: Boolean(options.watch),
    watchCount: options.watchCount ?? null,
    wakeGraceMultiplier: options.wakeGraceMultiplier ?? DEFAULT_WAKE_GRACE_MULTIPLIER,
    watchIntervalSeconds: options.watchIntervalSeconds ?? DEFAULT_WATCH_INTERVAL_SECONDS,
    writeDir: options.writeDir || null,
  };

View on GitHub (pinned to 8321021c54)