chenglou/pretext · error · Error
Invalid ACCURACY_CHECK_PORT: ${requestedPortRaw}
Error message
Invalid ACCURACY_CHECK_PORT: ${requestedPortRaw} What it means
Thrown by an IIFE at accuracy-check.ts:181-188 that parses the ACCURACY_CHECK_PORT environment variable. If the variable is set (not undefined) but Number.parseInt yields NaN (not finite), the value is unusable as a port and it throws immediately. An undefined variable is allowed (returns null, meaning 'pick any free port'); only a present-but-non-numeric value is rejected.
Source
Thrown at scripts/accuracy-check.ts:185
if (mismatch.diagnosticLines && mismatch.diagnosticLines.length > 0) {
for (const line of mismatch.diagnosticLines) {
console.log(` ${line}`)
}
}
}
}
let serverProcess: ChildProcess | null = null
let proxyServer: HttpServer | null = null
const lock = await acquireBrowserAutomationLock(browser)
const output = parseStringFlag('output')
const usePostedReport = includeFullRows
const requestedPortRaw = process.env['ACCURACY_CHECK_PORT']
const requestedPort = (() => {
if (requestedPortRaw === undefined) return null
const parsed = Number.parseInt(requestedPortRaw, 10)
if (!Number.isFinite(parsed)) {
throw new Error(`Invalid ACCURACY_CHECK_PORT: ${requestedPortRaw}`)
}
return parsed
})()
try {
let baseUrl: string
if (browser === 'firefox') {
const bunPort = await getAvailablePort()
const bunBaseUrl = `http://localhost:${bunPort}/accuracy`
serverProcess = spawn('/bin/zsh', ['-lc', `bun --port=${bunPort} --no-hmr pages/*.html`], {
cwd: process.cwd(),
stdio: 'ignore',
})
await waitForServer(bunBaseUrl)
const proxy = await startProxyServer(`http://[::1]:${bunPort}`)
proxyServer = proxy.serverView on GitHub (pinned to ac49b09b7d)
Solutions
- Set ACCURACY_CHECK_PORT to a concrete integer (e.g. 8080) or unset it entirely to let the script pick a free port.
- If the value comes from a template, default it: ACCURACY_CHECK_PORT="${ACCURACY_CHECK_PORT:-0}" and treat 0 as 'auto'.
- Audit .env files and CI secrets for an empty ACCURACY_CHECK_PORT assignment.
- Validate before exporting: only export when the value matches /^[0-9]+$/.
Example fix
# before export ACCURACY_CHECK_PORT= # after (unset to use auto, or set a real port) unset ACCURACY_CHECK_PORT # or export ACCURACY_CHECK_PORT=8080
Defensive patterns
Strategy: validation
Validate before calling
// Coerce and validate the env var before the script reads it.
const raw = process.env.ACCURACY_CHECK_PORT
const port = raw === undefined || raw === '' ? null : Number.parseInt(raw, 10)
if (port !== null && !Number.isFinite(port)) {
throw new Error(`Invalid ACCURACY_CHECK_PORT: ${raw}`)
} Type guard
function isValidPortEnv(raw: string | undefined): boolean {
return raw === undefined || raw === '' || /^\d+$/.test(raw)
} Try / catch
// The IIFE throws at module top-level; wrap the whole script entry or validate first.
const requestedPortRaw = process.env['ACCURACY_CHECK_PORT']
if (requestedPortRaw !== undefined && requestedPortRaw !== '' && !/^\d+$/.test(requestedPortRaw)) {
console.error(`Invalid ACCURACY_CHECK_PORT: ${requestedPortRaw}`)
process.exit(2)
} Prevention
- Default the env var with parameter expansion: ACCURACY_CHECK_PORT="${ACCURACY_CHECK_PORT:-}" and treat empty as auto.
- Audit .env and CI config for empty ACCURACY_CHECK_PORT assignments.
- Only export the variable when it matches /^[0-9]+$/.
When it happens
Trigger: Exporting ACCURACY_CHECK_PORT='' (empty string — parseInt('') is NaN), ACCURACY_CHECK_PORT=auto, ACCURACY_CHECK_PORT=any, or ACCURACY_CHECK_PORT=:8080. Note parseInt is lenient with trailing junk, so '8080abc' parses to 8080 and does NOT trip this guard; only values with no leading digits do.
Common situations: A CI matrix sets ACCURACY_CHECK_PORT from a templated variable that resolved to empty; a shell alias exports it unconditionally with a placeholder; copy-pasting a command that left the value blank; a .env file with `ACCURACY_CHECK_PORT=` (trailing nothing).
Related errors
- Invalid widths parameter: ${raw}
- Invalid value for --${name}: ${raw}
- Unsupported browser ${browser}; expected chrome or safari
- Invalid value for --runs: ${runs}; expected an integer >= 1
- Unknown corpus ${options.id}. Available corpora: ${sources.m
AI-assisted analysis of chenglou/pretext@ac49b09b7d (2026-08-12).
Data as JSON: /api/errors/af16c67a099313bb.
Report an issue: GitHub.