chenglou/pretext · error · Error

Invalid value for --${name}: ${raw}

Error message

Invalid value for --${name}: ${raw}

What it means

Thrown by the sweep's `parseNumberFlag` when a required numeric CLI flag is present but `Number.parseInt(raw, 10)` is not finite (non-numeric or empty). It covers `--start`, `--end`, `--step`, `--port`, `--timeout`, and `--diagnose-limit`.

Source

Thrown at scripts/corpus-sweep.ts:92

  timeoutMs: number
  font: string | null
  lineHeight: number | null
  diagnose: boolean
  diagnoseLimit: number
}

function parseStringFlag(name: string): string | null {
  const prefix = `--${name}=`
  const arg = process.argv.find(value => value.startsWith(prefix))
  return arg === undefined ? null : arg.slice(prefix.length)
}

function parseNumberFlag(name: string, fallback: number): number {
  const raw = parseStringFlag(name)
  if (raw === null) return fallback
  const parsed = Number.parseInt(raw, 10)
  if (!Number.isFinite(parsed)) {
    throw new Error(`Invalid value for --${name}: ${raw}`)
  }
  return parsed
}

function parseOptionalNumberFlag(name: string): number | null {
  const raw = parseStringFlag(name)
  if (raw === null) return null
  const parsed = Number.parseInt(raw, 10)
  if (!Number.isFinite(parsed)) {
    throw new Error(`Invalid value for --${name}: ${raw}`)
  }
  return parsed
}

function hasFlag(name: string): boolean {
  return process.argv.includes(`--${name}`)
}

View on GitHub (pinned to ac49b09b7d)

Solutions

  1. Pass a base-10 integer for the flagged option, e.g. `--step=10`.
  2. Strip any unit suffix; `--timeout` is milliseconds, so use `--timeout=180000` not `180s`.
  3. Check for a stray `=` with no value after it.

Example fix

// before
bun run scripts/corpus-sweep.ts --id=ja-kumo-no-ito --step=10px
// after
bun run scripts/corpus-sweep.ts --id=ja-kumo-no-ito --step=10
Defensive patterns

Strategy: validation

Validate before calling

function assertIntFlag(name: string): void {
  const raw = parseStringFlag(name)
  if (raw !== null && !/^-?\d+$/.test(raw)) {
    console.error(`--${name} must be a base-10 integer, got: ${raw}`)
    process.exit(2)
  }
}

Type guard

const isIntString = (v: string): boolean => /^-?\d+$/.test(v)

Prevention

When it happens

Trigger: Invoke `bun run scripts/corpus-sweep.ts --step=abc`, `--step=`, `--port=0x10`, or `--timeout=30s`. Any of these makes parseInt return NaN.

Common situations: Typo in a flag value; copy-pasting a unit suffix like `180s` (timeout is milliseconds); passing a hex value; a stray empty `--flag=`.

Related errors


AI-assisted analysis of chenglou/pretext@ac49b09b7d (2026-08-12). Data as JSON: /api/errors/a2a4a0decde94c33. Report an issue: GitHub.