chatboxai/chatbox · warning · ChatboxCliUsageError

--${name} must be between ${options.min} and ${options.max}.

Error message

--${name} must be between ${options.min} and ${options.max}.

What it means

Thrown by integerFlag() after the value passes the integer regex but falls outside the [min, max] range declared in the flag's options. It enforces bounded numeric arguments so consumers never receive out-of-contract values. The bounds are set per flag at definition time, not configurable by the end user.

Source

Thrown at src/renderer/packages/chatbox-cli/parser.ts:120

}

export function booleanFlag(parsed: ParsedArguments, name: string): boolean {
  return parsed.flags.get(name) === true
}

export function integerFlag(
  parsed: ParsedArguments,
  name: string,
  options: { defaultValue: number; min: number; max: number }
): number {
  const value = parsed.flags.get(name)
  if (value === undefined) return options.defaultValue
  if (typeof value !== 'string' || !/^\d+$/.test(value)) {
    throw new ChatboxCliUsageError(`--${name} must be an integer.`)
  }
  const result = Number(value)
  if (result < options.min || result > options.max) {
    throw new ChatboxCliUsageError(`--${name} must be between ${options.min} and ${options.max}.`)
  }
  return result
}

View on GitHub (pinned to 81571269ad)

Solutions

  1. Read the error message — it names the exact allowed range — and pass a value inside it.
  2. Confirm the flag's defined min/max in its command definition if the message's range seems wrong.
  3. If the legitimate use case needs a wider range, raise the {min,max} in the flag definition rather than bypassing the check.

Example fix

// before (flag defined min:1, max:100)
chatbox cmd --limit 500

// after
chatbox cmd --limit 100
Defensive patterns

Strategy: validation

Validate before calling

function withinRange(n: number, min: number, max: number): boolean {
  return Number.isInteger(n) && n >= min && n <= max
}
if (!withinRange(Number(raw), min, max)) { /* warn user, do not call */ }

Type guard

function isIntInRange(v: unknown, min: number, max: number): v is number {
  return typeof v === 'number' && Number.isInteger(v) && v >= min && v <= max
}

Try / catch

try {
  const limit = integerFlag(parsed, 'limit', { defaultValue: 10, min: 1, max: 100 })
} catch (e) {
  if (e instanceof ChatboxCliUsageError && e.message.includes('must be between')) {
    // prompt user for a value within range
  }
  throw e
}

Prevention

When it happens

Trigger: Calling a CLI command whose integerFlag has {min,max} and passing a value below min or above max, e.g. a flag defined with {min:1,max:100} invoked as `--flag 0` or `--flag 500`. The check is `result < options.min || result > options.max`.

Common situations: User copies a value from another tool's defaults that exceeds this tool's cap; user misreads the limit as 0-indexed; environment/script supplies a large batch size or port number beyond the allowed band.

Related errors


AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12). Data as JSON: /api/errors/d9fba9a4ca4493ab. Report an issue: GitHub.