chenglou/pretext · error · Error

corpus-check exited with status ${result.status ?? 'unknown'

Error message

corpus-check exited with status ${result.status ?? 'unknown'}

What it means

After `--diagnose` finds mismatches, the sweep spawns `scripts/corpus-check.ts` as a subprocess for detailed per-width diagnostics. This throws when that subprocess exits non-zero. The subprocess's stdout/stderr are already forwarded before the throw.

Source

Thrown at scripts/corpus-sweep.ts:236

  if (options.lineHeight !== null) {
    args.push(`--lineHeight=${options.lineHeight}`)
  }

  const result = spawnSync('bun', args, {
    cwd: process.cwd(),
    env: {
      ...process.env,
      CORPUS_CHECK_BROWSER: options.browser,
      CORPUS_CHECK_PORT: String(options.port),
      CORPUS_CHECK_TIMEOUT_MS: String(options.timeoutMs),
    },
    encoding: 'utf8',
  })

  if (result.stdout.length > 0) process.stdout.write(result.stdout)
  if (result.stderr.length > 0) process.stderr.write(result.stderr)
  if (result.status !== 0) {
    throw new Error(`corpus-check exited with status ${result.status ?? 'unknown'}`)
  }
}

const options = parseOptions()
options.port = await getAvailablePort(options.port === 0 ? null : options.port)
const sources = await loadSources()

const targets = options.all
  ? sources
  : (() => {
      if (options.id === null) {
        throw new Error(`Missing --id or --all. Available corpora: ${sources.map(source => source.id).join(', ')}`)
      }
      const meta = sources.find(source => source.id === options.id)
      if (meta === undefined) {
        throw new Error(`Unknown corpus ${options.id}. Available corpora: ${sources.map(source => source.id).join(', ')}`)
      }
      return [meta]

View on GitHub (pinned to ac49b09b7d)

Solutions

  1. Read the forwarded stdout/stderr above the error — they carry corpus-check's own failure reason.
  2. Ensure no other browser corpus job holds the automation lock or the configured port.
  3. Let the sweep auto-pick a free port (omit `--port` / use 0) so the subprocess doesn't collide.
  4. Re-run without `--diagnose` to confirm the sweep itself is healthy, then re-add `--diagnose`.
  5. Raise `--timeout` for the diagnose pass.

Example fix

// before: fixed port collides between sweep and its diagnose subprocess
CORPUS_CHECK_PORT=3210 bun run scripts/corpus-sweep.ts --id=... --diagnose
// after: let the sweep pick a free port
bun run scripts/corpus-sweep.ts --id=... --diagnose
Defensive patterns

Strategy: try-catch

Try / catch

const result = spawnSync('bun', args, { cwd: process.cwd(), encoding: 'utf8', env })
if (result.stdout.length > 0) process.stdout.write(result.stdout)
if (result.stderr.length > 0) process.stderr.write(result.stderr)
if (result.status !== 0) {
  // decide whether a diagnose failure should abort the whole sweep or just warn
  console.error(`corpus-check diagnose exited ${result.status ?? 'unknown'}; continuing without diagnostics`)
}

Prevention

When it happens

Trigger: Run `corpus-sweep.ts --diagnose` over a corpus with mismatches; the spawned `corpus-check.ts` itself crashes from a port conflict, browser-automation lock contention, or timeout.

Common situations: The diagnose subprocess inherits `CORPUS_CHECK_PORT`/`CORPUS_CHECK_TIMEOUT_MS`; a port already in use or a contended browser lock (the repo forbids parallel corpus jobs against one browser) makes corpus-check fail.

Related errors


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