{"record":{"id":"bb61ee4aef8a28ed","repo":"sinelaw/fresh","slug":"command-failed-with-exit-code","errorCode":null,"errorMessage":"Command failed with exit code: {:?}","messagePattern":"Command failed with exit code: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-editor/src/app/shell_command.rs","lineNumber":286,"sourceCode":"            .map_err(|e| anyhow::anyhow!(\"Failed to spawn shell: {}\", e))?;\n\n        let status = child\n            .wait()\n            .map_err(|e| anyhow::anyhow!(\"Failed to wait for command: {}\", e))?;\n\n        // Resume TUI — best-effort, nothing useful to do on failure.\n        #[allow(clippy::let_underscore_must_use)]\n        let _ = stdout().execute(EnterAlternateScreen);\n        #[allow(clippy::let_underscore_must_use)]\n        let _ = enable_raw_mode();\n\n        // Request a full hard redraw to clear any ghost text from the external command\n        self.request_full_redraw();\n\n        if status.success() {\n            Ok(())\n        } else {\n            anyhow::bail!(\"Command failed with exit code: {:?}\", status.code())\n        }\n    }\n}\n\n/// Detect the shell to use for executing commands.\nfn detect_shell() -> String {\n    // Try SHELL environment variable first\n    if let Ok(shell) = std::env::var(\"SHELL\") {\n        if !shell.is_empty() {\n            return shell;\n        }\n    }\n\n    // Fall back to common shells\n    #[cfg(unix)]\n    {\n        if std::path::Path::new(\"/bin/bash\").exists() {\n            return \"/bin/bash\".to_string();","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor/src/app/shell_command.rs#L268-L304","documentation":"run_shell_command_blocking runs an external shell command (suspending the TUI, restoring the shell, then waiting) and returns this error when the child process exits with a non-success status. The exit code is included in the message.","triggerScenarios":"Any :! command or shell integration whose child process exits non-zero — status.success() is false (non-zero exit code, or None when killed by a signal).","commonSituations":"Typo in the shell command (127 command not found); command fails on file permissions; lint/build tool invoked via :! returns non-zero; command killed by a signal (code None).","solutions":["Read the exit code in the error and run the command manually in a terminal to see its stderr.","Fix the command syntax/path so it exits 0.","If a non-zero exit is expected/acceptable, catch the error and proceed instead of propagating it."],"exampleFix":"// before\neditor.run_shell_command_blocking(\"make test\")?; // aborts on failure\n// after\nif let Err(e) = editor.run_shell_command_blocking(\"make test\") {\n    eprintln!(\"build command reported: {e}\"); // non-zero exit tolerated\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match editor.run_shell_command_blocking(cmd) { Err(e) if e.to_string().contains(\"Command failed with exit code\") => report_exit(e), Err(e) => return Err(e), Ok(()) => Ok(()) }","preventionTips":["Test shell commands outside the editor before binding them to keymaps","Check exit codes of build/lint tools run via :! commands","Remember a signal-killed process yields code None (e.g. \"exit code: None\")"],"tags":["shell","process","exit-code"],"backgroundTag":"git-command-failed","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}