{"record":{"id":"6ff52dd539bea1f6","repo":"nikivdev/code","slug":"bun-run-failed-with-status","errorCode":null,"errorMessage":"bun run {} failed with status {}","messagePattern":"bun run (.+?) failed with status (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/storage.rs","lineNumber":189,"sourceCode":"\nfn run_bun_script(project_dir: &Path, script: &str, database_url: Option<&str>) -> Result<()> {\n    let mut cmd = Command::new(\"bun\");\n    cmd.args([\"run\", script]);\n    cmd.current_dir(project_dir);\n    if let Some(url) = database_url {\n        cmd.env(\"DATABASE_URL\", url);\n    }\n    cmd.stdout(Stdio::inherit());\n    cmd.stderr(Stdio::inherit());\n    let status = cmd.status().with_context(|| {\n        format!(\n            \"failed to run bun script '{}' in {}\",\n            script,\n            project_dir.display()\n        )\n    })?;\n    if !status.success() {\n        bail!(\"bun run {} failed with status {}\", script, status);\n    }\n    Ok(())\n}\n\nfn jazz_new(\n    kind: JazzStorageKind,\n    name: Option<String>,\n    peer: Option<String>,\n    api_key: Option<String>,\n    environment: &str,\n) -> Result<()> {\n    let project = get_project_name()?;\n    let default_name = match kind {\n        JazzStorageKind::Mirror => format!(\"{}-jazz-mirror\", sanitize_name(&project)),\n        JazzStorageKind::EnvStore => format!(\"{}-jazz-env\", sanitize_name(&project)),\n        JazzStorageKind::AppStore => format!(\"{}-jazz-app\", sanitize_name(&project)),\n    };\n    let name = name.unwrap_or(default_name);","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/storage.rs#L171-L207","documentation":"run_bun_script shells out to `bun run <script>` inside the Postgres project directory (via Command::new(\"bun\")). If the child process exits with a non-zero status, the wrapper surfaces the script name and exit status as this error. It means the underlying bun script (e.g. drizzle-kit generate/migrate) itself failed.","triggerScenarios":"postgres_generate or postgres_migrate invoking run_bun_script where the spawned `bun run <script>` completes with status.success() == false — e.g. non-zero exit from drizzle-kit, missing script in package.json, or bun's own failure to start the script.","commonSituations":"Drizzle schema has a syntax error or invalid migration; drizzle-kit not installed (bun can't resolve the binary); package.json doesn't define the script being invoked; database unreachable causing migrate to fail; bun not on PATH (though that usually fails earlier at spawn).","solutions":["Re-run `bun run <script>` manually inside the project directory to see the full underlying error output.","Ensure dependencies are installed: `bun install` in the project directory (drizzle-kit present).","Verify the script name exists in the project's package.json scripts.","Fix the schema/migration or database connectivity problem that made the script exit non-zero."],"exampleFix":"// before\ncd services/postgres && myapp db generate\n// bun run db:generate failed with status 1\n// after — debug directly\ncd services/postgres && bun run db:generate  # shows real drizzle-kit error, fix it, then retry the CLI","handlingStrategy":"try-catch","validationCode":"const pkg = JSON.parse(fs.readFileSync(path.join(projectDir, 'package.json'), 'utf8'));\nif (!pkg.scripts?.[scriptName]) {\n  throw new Error(`Script \"${scriptName}\" not defined in ${projectDir}/package.json`);\n}\nif (!fs.existsSync(path.join(projectDir, 'node_modules'))) {\n  throw new Error('Dependencies not installed; run `bun install` first.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await postgresGenerate({ project });\n} catch (e) {\n  const m = String(e).match(/bun run (.+) failed with status (\\d+)/);\n  if (m) {\n    console.error(`bun script \"${m[1]}\" exited ${m[2]}. Re-run it directly for full output:`);\n    console.error(`  cd ${project} && bun run ${m[1]}`);\n    return;\n  }\n  throw e;\n}","preventionTips":["Run the underlying bun scripts locally before wiring them into CLI commands.","Keep drizzle-kit and other dev deps installed and pinned in the project.","Ensure package.json in the project directory defines the exact script names invoked.","Validate Drizzle schema files (compile/typecheck) before running generate/migrate in CI."],"tags":["process","bun","postgres","subprocess","exit-code"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}