chenglou/pretext · error · Error

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

Error message

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

What it means

parseNumberFlag (shared CLI helper in scripts/probe-check.ts) parses a --<name>=<raw> argument as a base-10 integer and throws when Number.parseInt(raw, 10) returns NaN. It guards --port, --width, and --lineHeight for the single-case diagnostic probe. Because it uses parseInt, '12.5' silently becomes 12 (no throw) while '', 'abc', '--', and '3px' all throw.

Source

Thrown at scripts/probe-check.ts:75

      unitWidth: number
      lineFitWidth: number
      marker: 'ours' | 'browser' | 'ours+browser' | null
    }[]
  } | null
  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 parseBrowser(value: string | null): BrowserKind {
  const browser = (value ?? process.env['PROBE_CHECK_BROWSER'] ?? 'chrome').toLowerCase()
  if (browser !== 'chrome' && browser !== 'safari') {
    throw new Error(`Unsupported browser ${browser}; expected chrome or safari`)
  }
  return browser
}

function requireFlag(name: string): string {
  const value = parseStringFlag(name)
  if (value === null || value.length === 0) throw new Error(`Missing --${name}=...`)
  return value
}

function printReport(report: ProbeReport): void {

View on GitHub (pinned to ac49b09b7d)

Solutions

  1. Pass a plain base-10 integer: --width=600, --port=0, --lineHeight=32.
  2. Remember numeric flags are unitless; keep CSS units on --font (e.g. --font=18px serif) only.
  3. Read the error message: it echoes the offending flag name and the raw value you passed.

Example fix

# before
bun run scripts/probe-check.ts --text=hi --width=600px --lineHeight=32

# after
bun run scripts/probe-check.ts --text=hi --width=600 --lineHeight=32
Defensive patterns

Strategy: validation

Validate before calling

const isIntFlag = (raw: string | null): boolean =>
  raw === null || /^-?\d+$/.test(raw.trim())
const raw = parseStringFlag('width')
if (!isIntFlag(raw)) {
  console.error(`--width expects an integer, got ${JSON.stringify(raw)}`)
  process.exit(2)
}

Type guard

const isIntFlag = (s: string | null): s is string =>
  s !== null && Number.isFinite(Number.parseInt(s, 10))

Prevention

When it happens

Trigger: bun run scripts/probe-check.ts --text=hi --width=abc; --port= (empty); --lineHeight=2em; any non-integer token for those three flags. parseNumberFlag is called at module top-level (lines 146,148,151), so the throw happens before any browser work starts.

Common situations: Typos in flag values; copy-pasting CSS units (18px) into a numeric flag; shell quoting that strips the value leaving --width=.

Related errors


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