{"record":{"id":"858c4dd84b4b589b","repo":"rust-lang/cargo","slug":"error-858c4d","errorCode":null,"errorMessage":"{}: {:?}","messagePattern":"\\{\\}: \\{:\\?\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/util/rustc.rs","lineNumber":267,"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":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/rust-lang/cargo/blob/42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9/src/util/rustc.rs#L249-L285","documentation":"Rustc::cached_output runs rustc/rustdoc and converts its captured stdout to a UTF-8 String. If stdout contains invalid UTF-8 bytes, the FromUtf8Error is wrapped (with the raw bytes shown for diagnostics) and contextualized with the failing command. The result is used for rustc info caching (version, host, etc.).","triggerScenarios":"rustc (or a RUSTC_WRAPPER / RUSTC_WORKSPACE_WRAPPER) emits non-UTF-8 bytes on stdout during the info probe that Cargo runs at startup.","commonSituations":"Locale set to a non-UTF-8 encoding (C/POSIX locale); a wrapper tool (sccache, build tooling) printing binary/banner data to stdout; a corrupted rustc; malicious/broken wrapper injecting arbitrary bytes.","solutions":["Set a UTF-8 locale: `export LC_ALL=C.UTF-8 LANG=C.UTF-8` (or en_US.UTF-8).","Check for a misbehaving RUSTC_WRAPPER / RUSTC_WORKSPACE_WRAPPER and remove or update it.","Reinstall/verify the rustc toolchain if output is genuinely corrupted."],"exampleFix":"# before\n# LC_ALL=POSIX cargo build   # rustc prints non-utf8 banner\n\n# after\n# export LC_ALL=C.UTF-8 LANG=C.UTF-8\n# cargo build","handlingStrategy":"validation","validationCode":"fn env_uses_utf8_locale() -> bool {\n    let loc = std::env::var(\"LC_ALL\").or_else(|_| std::env::var(\"LANG\"));\n    matches!(loc, Ok(s) if s.to_ascii_uppercase().contains(\"UTF-8\") || s.to_ascii_uppercase() == \"C.UTF-8\")\n}\n\n// before invoking cargo/rustc:\n// assert!(env_uses_utf8_locale(), \"set a UTF-8 locale to avoid rustc stdout decode errors\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always export a UTF-8 locale (LC_ALL=C.UTF-8 or en_US.UTF-8) in build environments.","Avoid RUSTC_WRAPPER tools that print non-UTF-8 banners to stdout.","In containers, install/generate a UTF-8 locale before running cargo."],"tags":["rustc","encoding","environment","utf8"],"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"}