jackwener/OpenCLI · error · ArgumentError

--duration must be an integer between 1 and 3600 seconds

Error message

--duration must be an integer between 1 and 3600 seconds

What it means

normalizeDuration in utils.js throws an ArgumentError when the --duration value is not an integer between 1 and 3600 seconds. Duration controls how long watch-mode streaming runs; the cap prevents runaway sessions of more than an hour.

Source

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

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

export function normalizeMaxChars(value, fallback = 6000) {
  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();

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer between 1 and 3600, e.g. --duration 300.
  2. Omit --duration to use the 30-second default.
  3. Convert minutes to seconds: 5 minutes -> --duration 300.
  4. For longer observation, loop multiple watch invocations capped at 3600 each.

Example fix

// before
opencli trae-cn watch --stream true --duration 0
// after
opencli trae-cn watch --stream true --duration 3600
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Running watch/stream commands with `--duration 0`, `--duration 7200`, `--duration 0.5`, `--duration forever`, or an empty-string value.

Common situations: Wanting an indefinite watch (--duration 0 or 999999); passing minutes instead of seconds (--duration 5 meaning 5 minutes); empty env interpolation.

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/b47e84d6030a9a5e. Report an issue: GitHub.