{"id":"858c4dd84b4b589b","repo":"rust-lang/cargo","slug":"error-858c4d","errorCode":null,"errorMessage":"{}: {:?}","messagePattern":"\\{\\}: \\{:\\?\\}","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/util/rustc.rs","lineNumber":283,"sourceCode":"                    dirty: false,\n                    data: CacheData::default(),\n                }\n            }\n        }\n    }\n\n    fn cached_output(\n        &mut self,\n        cmd: &ProcessBuilder,\n        extra_fingerprint: u64,\n    ) -> CargoResult<(String, String)> {\n        let key = process_fingerprint(cmd, extra_fingerprint);\n        if let std::collections::hash_map::Entry::Vacant(e) = self.data.outputs.entry(key) {\n            debug!(\"rustc info cache miss\");\n            debug!(\"running {}\", cmd);\n            let output = cmd.output()?;\n            let stdout = String::from_utf8(output.stdout)\n                .map_err(|e| anyhow::anyhow!(\"{}: {:?}\", e, e.as_bytes()))\n                .with_context(|| format!(\"`{}` didn't return utf8 output\", cmd))?;\n            let stderr = String::from_utf8(output.stderr)\n                .map_err(|e| anyhow::anyhow!(\"{}: {:?}\", e, e.as_bytes()))\n                .with_context(|| format!(\"`{}` didn't return utf8 output\", cmd))?;\n            e.insert(Output {\n                success: output.status.success(),\n                status: if output.status.success() {\n                    String::new()\n                } else {\n                    cargo_util::exit_status_to_string(output.status)\n                },\n                code: output.status.code(),\n                stdout,\n                stderr,\n            });\n            self.dirty = true;\n        } else {\n            debug!(\"rustc info cache hit\");","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/util/rustc.rs#L265-L301","documentation":"Cache::cached_output captures rustc's stdout as bytes and converts with String::from_utf8; if stdout is not valid UTF-8 it maps the Utf8Error to an anyhow formatting the error and the offending bytes (`{:?}`). The surrounding context notes which rustc command (`{cmd}`) produced the non-UTF-8 output. This typically indicates rustc emitted localized or binary output.","triggerScenarios":"Cargo runs rustc to query info (e.g. `rustc -vV`, `--print`, dep-info) and the rustc process writes non-UTF-8 bytes to stdout — e.g. a locale/localized rustc, a corrupted toolchain, or a custom RUSTC wrapper that emits binary data.","commonSituations":"A locale/env (`LC_ALL`, `LANG`) causing rustc to emit non-UTF-8 localized text; a misconfigured `RUSTC_WRAPPER`/`build.rustc-wrapper` that pollutes stdout; a broken/corrupt rustc binary; a rustc from a non-standard distribution.","solutions":["Set a UTF-8 locale: `export LC_ALL=C.UTF-8` (or `en_US.UTF-8`).","Remove or fix any `RUSTC_WRAPPER` / `build.rustc-wrapper` that writes non-UTF-8 to stdout (wrappers must keep stdout clean for cargo).","Reinstall/repair the toolchain with `rustup toolchain install`.","Run the failing rustc command manually and inspect its raw stdout bytes."],"exampleFix":"# before (wrapper pollutes stdout)\nexport RUSTC_WRAPPER=./my-wrapper\ncargo build\n\n# after (wrapper silent on stdout, or unset)\nunset RUSTC_WRAPPER\ncargo build","handlingStrategy":"validation","validationCode":"use std::process::Command;\nfn rustc_stdout_is_utf8(rustc: &str) -> Result<(), String> {\n    let out = Command::new(rustc).arg(\"-vV\").output().map_err(|e| e.to_string())?;\n    String::from_utf8(out.stdout).map(|_| ()).map_err(|e| format!(\"rustc stdout not UTF-8: {e}\"))\n}","typeGuard":"fn rustc_emits_utf8_stdout(rustc: &str) -> bool {\n    std::process::Command::new(rustc).arg(\"-vV\").output()\n        .map(|o| std::str::from_utf8(&o.stdout).is_ok()).unwrap_or(false)\n}","tryCatchPattern":"// Validate wrapper output before letting cargo cache it.\nif let Err(e) = String::from_utf8(stdout_bytes.clone()) {\n    eprintln!(\"rustc/wrapper stdout is not UTF-8 ({e}); fix the wrapper or locale\");\n}","preventionTips":["Set `LC_ALL=C.UTF-8` in CI and shells.","Keep `RUSTC_WRAPPER` stdout clean (it must only echo what rustc would).","Repair the toolchain if `rustc -vV` itself emits non-UTF-8."],"tags":["rustc","utf8","encoding","toolchain","wrapper"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}