jackwener/OpenCLI · error · ArgumentError

--interval must be an integer between 1 and 300 seconds

Error message

--interval must be an integer between 1 and 300 seconds

What it means

normalizeInterval in utils.js throws an ArgumentError when the --interval value is not an integer between 1 and 300 seconds. The interval is the polling frequency between activity checks during watch/stream; it must be at least 1s and at most 5 minutes.

Source

Thrown at clis/trae-cn/utils.js:64

  const maxChars = value === undefined || value === null ? fallback : Number(value);
  if (!Number.isInteger(maxChars) || maxChars < 0 || maxChars > 1_000_000) {
    throw new ArgumentError('--max-chars must be an integer between 0 and 1000000');
  }
  return maxChars;
}

export function normalizeDuration(value, fallback = 30) {
  const duration = value === undefined || value === null ? fallback : Number(value);
  if (!Number.isInteger(duration) || duration < 1 || duration > 3600) {
    throw new ArgumentError('--duration must be an integer between 1 and 3600 seconds');
  }
  return duration;
}

export function normalizeInterval(value, fallback = 2) {
  const interval = value === undefined || value === null ? fallback : Number(value);
  if (!Number.isInteger(interval) || interval < 1 || interval > 300) {
    throw new ArgumentError('--interval must be an integer between 1 and 300 seconds');
  }
  return interval;
}

export function normalizeApprovalKinds(value, fallback = TRAE_CN_APPROVAL_DEFAULT_KINDS.join(',')) {
  const raw = value === undefined || value === null || value === '' ? fallback : value;
  const parts = Array.isArray(raw) ? raw : String(raw).split(',');
  const expanded = [];
  for (const part of parts) {
    const item = String(part || '').trim().toLowerCase();
    if (!item) continue;
    if (item === 'all') {
      expanded.push('terminal', 'delete', 'keep');
      continue;
    }
    if (!['terminal', 'delete', 'keep'].includes(item)) {
      throw new ArgumentError('--approve-kinds must contain only terminal, delete, keep, or all');
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer between 1 and 300, e.g. --interval 2.
  2. Omit --interval to use the 2-second default.
  3. Accept the 1-second minimum for fastest polling: --interval 1.
  4. Fix scripts interpolating empty variables: --interval "${INTERVAL:-2}".

Example fix

// before
opencli trae-cn watch --interval 0
// after
opencli trae-cn watch --interval 1
Defensive patterns

Strategy: validation

Validate before calling

function assertInterval(v, fallback = 2) {
  const n = v === undefined || v === null ? fallback : Number(v);
  if (!Number.isInteger(n) || n < 1 || n > 300) throw new Error(`Invalid --interval: ${JSON.stringify(v)}; must be an integer 1-300 seconds`);
  return n;
}

Type guard

function isValidInterval(v) {
  return v === undefined || v === null ||
    (Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 300);
}

Try / catch

try {
  return await watchStream(interval);
} catch (e) {
  if (e instanceof ArgumentError && e.message.includes('--interval')) {
    return watchStream(Math.min(Math.max(Number(interval) || 2, 1), 300));
  }
  throw e;
}

Prevention

When it happens

Trigger: Running watch commands with `--interval 0` (trying to poll as fast as possible), `--interval 301`, `--interval 0.5`, or non-numeric values.

Common situations: Expecting sub-second polling with --interval 0 or 0.2; passing milliseconds (--interval 500); empty shell variables collapsing to 0.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/fb6df1198e706050. Report an issue: GitHub.