{"record":{"id":"5fa2f16387d1e4b0","repo":"nikivdev/code","slug":"tool-exited-with-status","errorCode":null,"errorMessage":"Tool '{}' exited with status: {}","messagePattern":"Tool '(.+?)' exited with status: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/tools.rs","lineNumber":144,"sourceCode":"    let tool_file = tools_dir.join(format!(\"{}.ts\", name));\n\n    if !tool_file.exists() {\n        bail!(\n            \"Tool '{}' not found. Create it with: f tools new {}\",\n            name,\n            name\n        );\n    }\n\n    let status = Command::new(\"bun\")\n        .arg(\"run\")\n        .arg(&tool_file)\n        .args(&args)\n        .status()\n        .context(\"failed to run bun\")?;\n\n    if !status.success() {\n        bail!(\"Tool '{}' exited with status: {}\", name, status);\n    }\n\n    Ok(())\n}\n\n/// Create a new tool.\nfn new_tool(name: &str, description: Option<&str>, use_ai: bool) -> Result<()> {\n    let tools_dir = get_tools_dir()?;\n    fs::create_dir_all(&tools_dir).context(\"failed to create tools directory\")?;\n\n    let tool_file = tools_dir.join(format!(\"{}.ts\", name));\n\n    if tool_file.exists() {\n        bail!(\"Tool '{}' already exists\", name);\n    }\n\n    if use_ai {\n        // Use localcode to generate the tool","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/tools.rs#L126-L162","documentation":"Raised by run_tool (src/tools.rs:144) when the bun subprocess running the tool's .ts file exits with a non-zero status. The tool itself (not the runner) failed — bun launched fine but the tool script returned an error exit code.","triggerScenarios":"Any `f <toolname>` invocation whose tool script exits non-zero: an uncaught TypeScript exception, an explicit process.exit(1), or a failed internal command within the tool. `status` (ExitStatus) is Display-formatted into the message.","commonSituations":"Tool script has a bug or unhandled rejection; tool's required env vars or API keys are missing; bun runtime version incompatibility with the tool's syntax/APIs; the tool delegates to a failing external command.","solutions":["Run the tool script directly to see its real error output: `bun <tools_dir>/<name>.ts <args>`.","Fix the bug or missing env/config in the tool's TypeScript source.","Check the bun version (`bun --version`) and upgrade if the tool needs newer APIs.","If the tool shells out to another program, verify that program's availability and exit code."],"exampleFix":"// before: tool crashes on missing env\nconst key = process.env.API_KEY; // undefined\nfetch(...)\n// after\nconst key = process.env.API_KEY;\nif (!key) { console.error(\"API_KEY required\"); process.exit(1); }","handlingStrategy":"try-catch","validationCode":"// dry-run the tool via bun first to surface its errors\ntry {\n  execSync(`bun ${toolsDir}/${name}.ts --help`, { stdio: \"inherit\" });\n} catch (e) {\n  console.error(\"tool itself fails under bun; fix the script first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  runTool(name, args);\n} catch (e) {\n  if (String(e).includes(\"exited with status\")) {\n    console.error(`tool ${name} failed; run: bun ${toolsDir}/${name}.ts for the real error`);\n  } else throw e;\n}","preventionTips":["Keep bun up to date and consistent with the tool's requirements.","Add error handling and clear process.exit codes inside each tool script.","Verify required env vars/keys inside the tool before doing work.","Smoke-test tools after editing them."],"tags":["subprocess","bun","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"}