chenglou/pretext · error · Error

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

Error message

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

What it means

parseNumberFlag() in keep-all-check.ts parses a `--<name>=<value>` CLI argument as a base-10 integer and throws when the result is not finite (NaN). This guards the numeric flags (port, timeout) so a malformed value fails fast with a clear message instead of silently becoming NaN downstream.

Source

Thrown at scripts/keep-all-check.ts:55

  requestId?: string
  results?: Array<{
    label: string
    report: ProbeReport
  }>
  message?: string
}

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 parseBrowsers(value: string | null): AutomationBrowserKind[] {
  const raw = (value ?? 'chrome,safari').trim()
  if (raw.length === 0) return ['chrome', 'safari']

  const browsers = raw
    .split(',')
    .map(part => part.trim().toLowerCase())
    .filter(Boolean)

  for (const browser of browsers) {
    if (browser !== 'chrome' && browser !== 'safari' && browser !== 'firefox') {
      throw new Error(`Unsupported browser ${browser}`)
    }
  }

View on GitHub (pinned to ac49b09b7d)

Solutions

  1. Re-run supplying an integer for the flagged option, e.g. `--port=3210` or `--timeout=60000`.
  2. If you want the default, simply omit the flag rather than passing `--port=`.
  3. Check the exact flag name in the error message and confirm it is one of port/timeout supported by keep-all-check.ts.

Example fix

# before
bun run keep-all-check -- --port=auto

# after
bun run keep-all-check -- --port=3210
Defensive patterns

Strategy: validation

Validate before calling

function readNumberFlag(name: string, fallback: number): number {
  const prefix = `--${name}=`
  const arg = process.argv.find(v => v.startsWith(prefix))
  if (arg === undefined) return fallback
  const raw = arg.slice(prefix.length)
  const n = Number.parseInt(raw, 10)
  if (!Number.isFinite(n)) {
    console.error(`--${name} expects an integer, got: ${JSON.stringify(raw)}`)
    process.exit(2)
  }
  return n
}

Type guard

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

Prevention

When it happens

Trigger: Invoking `bun run keep-all-check -- --port=abc`, `--port=` (empty), `--timeout=soon`, or any value where Number.parseInt yields NaN. A non-empty string of pure whitespace like `--port= ` also parses to NaN.

Common situations: A typo in a Makefile/npm-script flag, a copied command with a stale placeholder, or a shell variable that expanded to empty.

Related errors


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