{"record":{"id":"063453f605417cc3","repo":"vercel/next.js","slug":"command-failed-command-args-join-exit","errorCode":null,"errorMessage":"Command failed: ${command} ${args.join(' ')} (exit ${code})","messagePattern":"Command failed: (.+?) (.+?) \\(exit (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bench/render-pipeline/benchmark.ts","lineNumber":280,"sourceCode":"  const stddev = Math.sqrt(variance)\n  const p95 = sorted[Math.max(0, Math.ceil(sorted.length * 0.95) - 1)]\n  return { min, median, mean, stddev, p95, max }\n}\n\nasync function runCommand(\n  command: string,\n  args: string[],\n  cwd: string,\n  env: NodeJS.ProcessEnv = process.env\n): Promise<void> {\n  const child = spawn(command, args, {\n    cwd,\n    env,\n    stdio: 'inherit',\n  })\n  const [code] = (await once(child, 'exit')) as [number | null]\n  if (code !== 0) {\n    throw new Error(\n      `Command failed: ${command} ${args.join(' ')} (exit ${code})`\n    )\n  }\n}\n\nasync function ensureNextBuilt() {\n  try {\n    await access(NEXT_BIN)\n  } catch {\n    throw new Error(\n      `Missing ${NEXT_BIN}. Build Next.js first (pnpm --filter=next build).`\n    )\n  }\n}\n\nasync function waitForServerReady(\n  url: string,\n  timeoutMs: number,","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/bench/render-pipeline/benchmark.ts#L262-L298","documentation":"Thrown by runCommand (benchmark.ts:280) when a spawned subprocess (the generate-client-graph script, `next build`, or other node invocations via runCommand) exits with a non-zero code. The message includes the command, its args, and the exit code. The subprocess inherits stdio so its own error output appears above this throw, making the exit cause visible.","triggerScenarios":"ensureGeneratedClientGraph running scripts/generate-client-graph.mjs that exits non-zero; `next build` failing on the basic-app fixture (build error in the app); any other runCommand call. Because stdio is 'inherit', the real failure text scrolls by before this error.","commonSituations":"A broken fixture app that fails to build; the client-graph generator script has a bug or hits a missing dependency; a Next.js source change that breaks the basic-app build; running against an unbuilt NEXT_BIN so `next build` itself errors.","solutions":["Scroll up: the subprocess printed the real error (build error, missing module, etc.) to stdout/stderr before this throw — fix that.","Reproduce manually: run the exact command + args from the message in the same cwd.","If it's `next build`, ensure NEXT_BIN exists (pnpm --filter=next build) and the basic-app fixture is in sync with current Next.js.","If it's the generator, run `node bench/basic-app/scripts/generate-client-graph.mjs` by hand to see the failure."],"exampleFix":"# before — opaque failure\n#   Error: Command failed: node [...]/generate-client-graph.mjs (exit 1)\n\n# reproduce to find the real cause\nnode bench/basic-app/scripts/generate-client-graph.mjs\n# then fix the script/app, then re-run the benchmark","handlingStrategy":"try-catch","validationCode":"// pre-flight the things runCommand will invoke:\nimport { existsSync } from 'node:fs'\nif (!existsSync(NEXT_BIN)) throw new Error('NEXT_BIN missing — build first')\nif (!existsSync(resolve(options.appDir, 'scripts/generate-client-graph.mjs'))) {/* optional generator */}\n// for next build, you can dry-check the fixture compiles via `next build` manually first","typeGuard":"function isCommandFailure(err: unknown): err is Error {\n  return err instanceof Error && err.message.startsWith('Command failed:')\n}","tryCatchPattern":"try {\n  await runCommand('node', [NEXT_BIN, 'build'], options.appDir, env)\n} catch (err) {\n  if (isCommandFailure(err)) {\n    // the subprocess already printed its error to inherited stdio; just annotate\n    console.error('\\nThe command above exited non-zero. See its output above for the cause.')\n  }\n  throw err\n}","preventionTips":["Reproduce the failing command manually (copy command + args from the message) to see the real error in context.","Keep the fixture app (bench/basic-app) in sync with current Next.js so `next build` stays green.","Ensure NEXT_BIN is built before benchmarking (error [13]).","Don't suppress inherited stdio for build steps — the failure text is the diagnosis."],"tags":["subprocess","build","render-pipeline","spawn","exit-code"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}