{"record":{"id":"a61a6b8a92bfb1af","repo":"bensadeh/tailspin","slug":"exec-command-failed-status","errorCode":null,"errorMessage":"--exec command failed ({status})","messagePattern":"--exec command failed \\((.+?)\\)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/io/reader/command.rs","lineNumber":34,"sourceCode":"    pub fn new(command: String) -> Result<CommandReader> {\n        spawn_command(command)\n    }\n\n    pub fn child(&self) -> Arc<SharedChild> {\n        self.child.clone()\n    }\n\n    pub fn next(&mut self) -> Result<StreamEvent> {\n        if !self.initial_read_complete_sent {\n            self.initial_read_complete_sent = true;\n\n            return Ok(StreamEvent::InitialReadComplete);\n        }\n\n        let event = match read_batch(&mut self.reader)? {\n            ReadResult::Eof => {\n                let status = self.child.wait()?;\n                ensure!(status.success(), \"--exec command failed ({status})\");\n                StreamEvent::Ended\n            }\n            ReadResult::Batch(batch) => StreamEvent::Lines(batch),\n        };\n\n        Ok(event)\n    }\n}\n\n#[cfg(not(windows))]\nfn spawn_command(command: String) -> Result<CommandReader> {\n    use crate::io::reader::line_batcher::BUF_READER_CAPACITY;\n    use anyhow::Context;\n    use std::process::{Command, Stdio};\n\n    let trap_command = format!(\"trap '' INT; {command}\");\n\n    let mut sh = Command::new(\"sh\");","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/bensadeh/tailspin/blob/8ecaa9a8a1bf3ba1e7457a20de11d2df75327d81/src/io/reader/command.rs#L16-L52","documentation":"This error is thrown when the external process spawned via --exec exits with a non-zero status after the reader has consumed all of its output. The library waits on the child process and requires a successful exit; any non-zero exit code means the command itself failed mid-stream, so the read pipeline reports the failure instead of returning partial data as success.","triggerScenarios":"Running a pager session where the --exec command finishes but exits with a non-zero exit status (e.g. the command crashes, is killed by a signal, or calls exit(1)). Specifically triggered in CommandReader::next when read_batch returns Eof and child.wait() yields a failing ExitStatus.","commonSituations":"The user passes a shell command with a typo that fails late in execution; the command hits an internal error after producing some output; the command is terminated by SIGSEGV/SIGKILL; a script under --exec ends with a failing subcommand.","solutions":["Run the --exec command manually and check its exit code to see why it fails","Fix the bug or typo in the command so it exits 0 on success","If non-zero exits are expected/harmless, wrap the command so it exits 0, e.g. append '|| true' in a shell wrapper","Check whether the command was killed by a signal (status reported in the message) and address resource limits (OOM, disk)"],"exampleFix":"// before\nmyapp --exec \"cat data.txt; grep missing-pattern\"\n// after\nmyapp --exec \"cat data.txt; grep missing-pattern || true\"","handlingStrategy":"try-catch","validationCode":"mycmd; echo \"exit=$?\"  # run the --exec command standalone first and confirm exit code 0","typeGuard":null,"tryCatchPattern":"match reader.next() {\n    Err(e) if e.to_string().contains(\"--exec command failed\") => {\n        eprintln!(\"underlying command exited nonzero: {e}\");\n        // inspect/repair the command, or fall back to reading from a file\n    }\n    Err(e) => return Err(e),\n    Ok(ev) => { /* handle event */ }\n}","preventionTips":["Always smoke-test the --exec command in a shell and confirm exit code 0","Avoid commands that can fail late (grep with no matches, diff on differing files); append '|| true' when the exit code is not meaningful","Watch for signals: ensure the command is not OOM-killed or killed by timeouts","Log the captured ExitStatus for diagnostics in wrappers around the tool"],"tags":["subprocess","exit-status","process-execution"],"backgroundTag":"command-exit-status-nonzero","analyzedSha":"8ecaa9a8a1bf3ba1e7457a20de11d2df75327d81","analyzedAt":"2026-09-13T19:04:00.202Z","contentChangedAt":"2026-09-13T19:04:00.202Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}