{"record":{"id":"d122257b12b05a5c","repo":"rust-lang/cargo","slug":"failed-to-parse-process-output","errorCode":null,"errorMessage":"failed to parse process output: {}","messagePattern":"failed to parse process output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cargo-util/src/process_builder.rs","lineNumber":472,"sourceCode":"            }\n            status\n        })()\n        .with_context(|| ProcessError::could_not_execute(self))?;\n        let output = Output {\n            status,\n            stdout,\n            stderr,\n        };\n\n        {\n            let to_print = if capture_output { Some(&output) } else { None };\n            if let Some(e) = callback_error {\n                let cx = ProcessError::new(\n                    &format!(\"failed to parse process output: {}\", self),\n                    Some(output.status),\n                    to_print,\n                );\n                bail!(anyhow::Error::new(cx).context(e));\n            } else if !output.status.success() {\n                bail!(ProcessError::new(\n                    &format!(\"process didn't exit successfully: {}\", self),\n                    Some(output.status),\n                    to_print,\n                ));\n            }\n        }\n\n        Ok(output)\n    }\n\n    /// Builds the command with an `@<path>` argfile that contains all the\n    /// arguments. This is primarily served for rustc/rustdoc command family.\n    fn build_command_with_argfile(&self) -> io::Result<(Command, NamedTempFile)> {\n        use std::io::Write as _;\n\n        let mut tmp = tempfile::Builder::new()","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/rust-lang/cargo/blob/42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9/crates/cargo-util/src/process_builder.rs#L454-L490","documentation":"process_builder's execute_with_callback captures stdout/stderr; if the callback itself returns an error (callback_error), Cargo wraps it as a ProcessError with the message 'failed to parse process output: {process}'. This indicates the child process ran but its output could not be parsed by the caller-supplied callback.","triggerScenarios":"Invoking an external process via ProcessBuilder with an output-parsing callback that returns Err (e.g. JSON parse failure, unexpected stdout format). The error is propagated with this message.","commonSituations":"Parsing `rustc --print` / `cargo metadata` / `git` output where the format changed across versions; partial/empty stdout due to process crash; locale-dependent output; version skew between expected and actual tool output.","solutions":["Capture and inspect the raw stdout/stderr of the failing process to see what could not be parsed.","Align the parser with the actual tool version/output format.","Ensure the invoked tool is the expected version and locale (e.g. LC_ALL=C) so output is stable.","Handle the error in the callback by returning a clearer message or falling back."],"exampleFix":"// before\nlet output = process.exec_with_streaming(&mut |stdout| parse(stdout), ...)?;\n// after\nlet output = process.exec_with_streaming(&mut |stdout| {\n    parse(stdout).map_err(|e| format_err!(\"parse failed for line: {e}\"))\n}, ...)?;","handlingStrategy":"try-catch","validationCode":"// Run the process with output captured for diagnostics first\nlet out = process.output()?;\nif !out.status.success() || std::str::from_utf8(&out.stdout).is_err() {\n    eprintln!(\"stdout: {:?}\", String::from_utf8_lossy(&out.stdout));\n}","typeGuard":"null","tryCatchPattern":"match process.exec_with_streaming(&mut |s| parse(s), ...) {\n    Ok(v) => v,\n    Err(e) => {\n        // re-run capturing raw output to diagnose parse failure\n        log::warn!(\"parse callback failed: {e:#}\");\n        return Err(e);\n    }\n}","preventionTips":["Pin the external tool version whose output you parse.","Pin locale (LC_ALL=C) for stable output.","Log raw stdout/stderr alongside parse errors."],"tags":["cargo","process","subprocess","parsing","external-tool"],"backgroundTag":null,"analyzedSha":"42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}