{"record":{"id":"3b267937235b4368","repo":"sigoden/aichat","slug":"the-command-cmd-eval-exited-with-non-zero","errorCode":null,"errorMessage":"The command `{cmd_eval}` exited with non-zero.","messagePattern":"The command `(.+?)` exited with non-zero\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/command.rs","lineNumber":149,"sourceCode":"        let (success, stdout, stderr) =\n            run_command_with_output(cmd, args, None).with_context(|| {\n                format!(\"Unable to run `{cmd_eval}`, Perhaps '{cmd}' is not installed?\")\n            })?;\n        if !success {\n            let err = if !stderr.is_empty() {\n                stderr\n            } else {\n                format!(\"The command `{cmd_eval}` exited with non-zero.\")\n            };\n            bail!(\"{err}\")\n        }\n        Ok(stdout)\n    } else {\n        let status = run_command(cmd, args, None).with_context(|| {\n            format!(\"Unable to run `{cmd_eval}`, Perhaps '{cmd}' is not installed?\")\n        })?;\n        if status != 0 {\n            bail!(\"The command `{cmd_eval}` exited with non-zero.\")\n        }\n        let contents = std::fs::read_to_string(&outpath)\n            .context(\"Failed to read file generated by the loader\")?;\n        Ok(contents)\n    }\n}\n\npub fn edit_file(editor: &str, path: &Path) -> Result<()> {\n    let mut child = Command::new(editor).arg(path).spawn()?;\n    child.wait()?;\n    Ok(())\n}\n\npub fn append_to_shell_history(shell: &str, command: &str, exit_code: i32) -> io::Result<()> {\n    if let Some(history_file) = get_history_file(shell) {\n        let command = command.replace('\\n', \" \");\n        let now = now_timestamp();\n        let history_txt = if shell == \"fish\" {","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/utils/command.rs#L131-L167","documentation":"In the branch of run_loader_command where the command writes output to a file, a non-zero exit status produces this bail (stderr is not captured in this path). The message tells you which command failed but not why.","triggerScenarios":"A loader command configured to write to an output file exits with status != 0 during load_with_command / load_protocol_path / fetch_with_loaders.","commonSituations":"Loader crashes or rejects the input silently; command not found behaviors handled earlier but other failures (bad flags, permissions) exit non-zero; environment differences between interactive shell and spawned process.","solutions":["Re-run the same command manually and check its exit code/stderr","Fix the loader's arguments or input so it exits 0","Ensure the output path is writable and the loader can create the file","Check that required env vars for the loader are set in the spawning environment"],"exampleFix":"// before: failing flags\nloader = [\"pandoc\", \"--bad-flag\"]\n// after\nloader = [\"pandoc\", \"-f\", \"html\", \"-t\", \"markdown\"]","handlingStrategy":"try-catch","validationCode":"// smoke-test the command with the same args and check exit code\nconst r = spawnSync(cmd, args, { stdio: 'ignore' });\nif (r.status !== 0) console.error(`${cmd} exits ${r.status}`);","typeGuard":null,"tryCatchPattern":"try {\n  const contents = await loadFromCommand(cmd, args);\n} catch (e) {\n  if (e.message.includes('exited with non-zero')) {\n    // re-run manually for stderr since this path hides it\n  }\n}","preventionTips":["Ensure commands exit 0 on success and write to the expected output file","Avoid flags that only work in interactive shells","Set required env vars in the service environment, not just your shell"],"tags":["external-command","loader","exit-code","process"],"backgroundTag":"git-command-failed","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}