{"record":{"id":"2b5c20cd0c14fdd2","repo":"chenglou/pretext","slug":"corpus-check-exited-with-status-result-status","errorCode":null,"errorMessage":"corpus-check exited with status ${result.status ?? 'unknown'}","messagePattern":"corpus-check exited with status (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/corpus-sweep.ts","lineNumber":236,"sourceCode":"  if (options.lineHeight !== null) {\n    args.push(`--lineHeight=${options.lineHeight}`)\n  }\n\n  const result = spawnSync('bun', args, {\n    cwd: process.cwd(),\n    env: {\n      ...process.env,\n      CORPUS_CHECK_BROWSER: options.browser,\n      CORPUS_CHECK_PORT: String(options.port),\n      CORPUS_CHECK_TIMEOUT_MS: String(options.timeoutMs),\n    },\n    encoding: 'utf8',\n  })\n\n  if (result.stdout.length > 0) process.stdout.write(result.stdout)\n  if (result.stderr.length > 0) process.stderr.write(result.stderr)\n  if (result.status !== 0) {\n    throw new Error(`corpus-check exited with status ${result.status ?? 'unknown'}`)\n  }\n}\n\nconst options = parseOptions()\noptions.port = await getAvailablePort(options.port === 0 ? null : options.port)\nconst sources = await loadSources()\n\nconst targets = options.all\n  ? sources\n  : (() => {\n      if (options.id === null) {\n        throw new Error(`Missing --id or --all. Available corpora: ${sources.map(source => source.id).join(', ')}`)\n      }\n      const meta = sources.find(source => source.id === options.id)\n      if (meta === undefined) {\n        throw new Error(`Unknown corpus ${options.id}. Available corpora: ${sources.map(source => source.id).join(', ')}`)\n      }\n      return [meta]","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/scripts/corpus-sweep.ts#L218-L254","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the forwarded stdout/stderr above the error — they carry corpus-check's own failure reason.","Ensure no other browser corpus job holds the automation lock or the configured port.","Let the sweep auto-pick a free port (omit `--port` / use 0) so the subprocess doesn't collide.","Re-run without `--diagnose` to confirm the sweep itself is healthy, then re-add `--diagnose`.","Raise `--timeout` for the diagnose pass."],"exampleFix":"// before: fixed port collides between sweep and its diagnose subprocess\nCORPUS_CHECK_PORT=3210 bun run scripts/corpus-sweep.ts --id=... --diagnose\n// after: let the sweep pick a free port\nbun run scripts/corpus-sweep.ts --id=... --diagnose","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const result = spawnSync('bun', args, { cwd: process.cwd(), encoding: 'utf8', env })\nif (result.stdout.length > 0) process.stdout.write(result.stdout)\nif (result.stderr.length > 0) process.stderr.write(result.stderr)\nif (result.status !== 0) {\n  // decide whether a diagnose failure should abort the whole sweep or just warn\n  console.error(`corpus-check diagnose exited ${result.status ?? 'unknown'}; continuing without diagnostics`)\n}","preventionTips":["Never run parallel corpus jobs against the same browser; they contend for the automation lock and port.","Let the sweep auto-pick a free port (omit --port) so the diagnose subprocess doesn't collide.","Raise --timeout for large diagnose passes.","Read the forwarded subprocess stdout/stderr before treating the status as opaque."],"tags":["corpus","subprocess","diagnose","browser-automation"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}