{"id":"479f12aa1bdcb259","repo":"BurntSushi/ripgrep","slug":"preprocessor-command-failed-cmd-err","errorCode":null,"errorMessage":"preprocessor command failed: '{cmd:?}': {err}","messagePattern":"preprocessor command failed: '(.+?)': (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/core/search.rs","lineNumber":315,"sourceCode":"        &mut self,\n        path: &Path,\n    ) -> io::Result<SearchResult> {\n        use std::{fs::File, process::Stdio};\n\n        let bin = self.config.preprocessor.as_ref().unwrap();\n        let mut cmd = std::process::Command::new(bin);\n        cmd.arg(path).stdin(Stdio::from(File::open(path)?));\n\n        let mut rdr = self.command_builder.build(&mut cmd).map_err(|err| {\n            io::Error::new(\n                io::ErrorKind::Other,\n                format!(\n                    \"preprocessor command could not start: '{cmd:?}': {err}\",\n                ),\n            )\n        })?;\n        let result = self.search_reader(path, &mut rdr).map_err(|err| {\n            io::Error::new(\n                io::ErrorKind::Other,\n                format!(\"preprocessor command failed: '{cmd:?}': {err}\"),\n            )\n        });\n        let close_result = rdr.close();\n        let search_result = result?;\n        close_result?;\n        Ok(search_result)\n    }\n\n    /// Attempt to decompress the data at the given file path and search the\n    /// result. If the given file path isn't recognized as a compressed file,\n    /// then search it without doing any decompression.\n    fn search_decompress(&mut self, path: &Path) -> io::Result<SearchResult> {\n        let Some(ref decomp_builder) = self.decomp_builder else {\n            return self.search_path(path);\n        };\n        let mut rdr = decomp_builder.build(path)?;","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/BurntSushi/ripgrep/blob/3fce3b5bb0236da2df6d99672afb8a719642eca7/crates/core/search.rs#L297-L333","documentation":"In search_preprocessor, after the command spawns successfully, search_reader runs over the preprocessor's stdout. If reading or searching that stream fails (preprocessor exited non-zero, closed stdout early, wrote invalid data), the error is wrapped as format!(\"preprocessor command failed: '{cmd:?}': {err}\"). It signals the preprocessor ran but did not produce usable output.","triggerScenarios":"The preprocessor binary starts but crashes, exits non-zero, is killed (OOM), or closes its stdout pipe before emitting all data, causing search_reader (or the subsequent rdr.close()) to observe an IO error.","commonSituations":"A preprocessor script with a bug that panics; a decompressor failing on a truncated archive; a wrapper that requires args the caller did not pass; memory pressure killing the child.","solutions":["Run the preprocessor manually on the same file (preprocessor <file>) and inspect its exit code and stderr.","Fix the script so it exits 0 and writes complete output to stdout.","Ensure the preprocessor does not close stdout prematurely and handles the file argument correctly."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = search_preprocessor(path) {\n    eprintln!(\"{e}\"); // command failed mid-run\n}","preventionTips":["Make the preprocessor exit 0 and write complete output to stdout.","Handle the file-path argument robustly in the script (no panics on edge cases).","Capture and log the preprocessor's own stderr to diagnose mid-run failures."],"tags":["preprocessor","process","io","cli"],"analyzedSha":"3fce3b5bb0236da2df6d99672afb8a719642eca7","analyzedAt":"2026-08-06T01:39:05.073Z","schemaVersion":2}