{"record":{"id":"9b149368344199f2","repo":"mastra-ai/mastra","slug":"label-command-failed-exit-result-exitcode","errorCode":null,"errorMessage":"${label} command failed (exit ${result.exitCode}): ${detail}","messagePattern":"(.+?) command failed \\(exit (.+?)\\): (.+?)","errorType":"exception","errorClass":"SetupCommandError","httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/integrations/github/sandbox.ts","lineNumber":835,"sourceCode":" *\n * @param sandbox  live sandbox containing the checkout\n * @param workdir  the server-resolved session workdir the command runs in\n * @param command  the org-configured setup shell command\n */\nasync function runLifecycleCommand(\n  sandbox: ExecutableSandbox,\n  workdir: string,\n  command: string,\n  options: { phase: 'setup' | 'teardown'; timeoutMs?: number },\n): Promise<void> {\n  const result = await sh(sandbox, `cd ${shellQuote(workdir)} && { ${command}\\n}`, {\n    phase: `${options.phase} command`,\n    ...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),\n  });\n  if (result.exitCode !== 0) {\n    const detail = (result.stderr.trim() || result.stdout.trim()).slice(-1800);\n    const label = options.phase === 'setup' ? 'Setup' : 'Teardown';\n    throw new SetupCommandError(\n      `${label} command failed (exit ${result.exitCode}): ${detail}`,\n      options.phase === 'setup' ? 'setup-failed' : 'teardown-failed',\n    );\n  }\n}\n\nexport async function runSetupCommand(\n  sandbox: ExecutableSandbox,\n  workdir: string,\n  command: string,\n): Promise<void> {\n  return runLifecycleCommand(sandbox, workdir, command, { phase: 'setup' });\n}\n\n/**\n * Run the repository's best-effort teardown command from the materialized\n * session workdir. Callers own lifecycle policy: this helper reports failures\n * so the retirement coordinator can log them while still continuing with","sourceCodeStart":817,"sourceCodeEnd":853,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/integrations/github/sandbox.ts#L817-L853","documentation":"A setup or teardown command run inside the sandbox exited non-zero; the code captures the last 1800 chars of stderr (or stdout) and throws SetupCommandError with code 'setup-failed' or 'teardown-failed'. The library uses this to surface exactly which phase (setup vs teardown) and which command failed during project build preparation.","triggerScenarios":"Any command in the setup or teardown phase returns a non-zero exit code — package install failures (npm/pnpm install), build script errors, or missing tools in the sandbox template.","commonSituations":"Dependency install fails due to registry auth or network; build fails on type errors; tool required by the phase (e.g. pnpm) not installed in the sandbox image.","solutions":["Read the exit code and trailing stderr in the message to identify the failing command","Re-run locally to reproduce (e.g. run the same install/build command in a matching container)","Ensure the sandbox template includes all required tools for the phase","Fix the underlying build/dependency error the output points to, then retry"],"exampleFix":"// before\n// Setup command failed (exit 1): pnpm: not found\n// after (sandbox template Dockerfile)\nRUN corepack enable && corepack prepare pnpm@latest --activate","handlingStrategy":"try-catch","validationCode":"const which = await sh(sandbox, 'sh -c \"command -v pnpm npm node git\"');\nif (which.exitCode !== 0) throw new Error('required tools missing in sandbox');","typeGuard":null,"tryCatchPattern":"try {\n  await runSetup(sandbox, options);\n} catch (e) {\n  if (e instanceof SetupCommandError && e.code === 'setup-failed') {\n    // e.message ends with the last 1800 chars of the command output; read it to find the failing step\n  }\n  throw e;\n}","preventionTips":["Bake all required tools into the sandbox template image","Run setup commands once locally in the same base image before shipping","Keep phase commands small so failures are easy to localize from the output tail"],"tags":["sandbox","shell","build"],"backgroundTag":"setup-command-exited-nonzero","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}