{"record":{"id":"51bbe08208e855ec","repo":"zed-industries/zed","slug":"prompt-file-is-not-valid-utf-8","errorCode":null,"errorMessage":"prompt file is not valid UTF-8","messagePattern":"prompt file is not valid UTF-8","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/edit_prediction_cli/src/prompt_assets.rs","lineNumber":38,"sourceCode":"        .context(name)\n        .expect(\"Failed to read prompt\");\n    let leaked = contents.leak();\n    PROMPT_CACHE.write().unwrap().insert(name, leaked);\n    return Cow::Borrowed(leaked);\n}\n\n#[cfg(not(feature = \"dynamic_prompts\"))]\npub fn get_prompt(name: &'static str) -> Cow<'static, str> {\n    use rust_embed::RustEmbed;\n\n    #[derive(RustEmbed)]\n    #[folder = \"src/prompts\"]\n    struct EmbeddedPrompts;\n\n    match EmbeddedPrompts::get(name) {\n        Some(file) => match file.data {\n            Cow::Borrowed(bytes) => {\n                Cow::Borrowed(std::str::from_utf8(bytes).expect(\"prompt file is not valid UTF-8\"))\n            }\n            Cow::Owned(bytes) => {\n                Cow::Owned(String::from_utf8(bytes).expect(\"prompt file is not valid UTF-8\"))\n            }\n        },\n        None => panic!(\"prompt file not found: {name}\"),\n    }\n}\n","sourceCodeStart":20,"sourceCodeEnd":47,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/edit_prediction_cli/src/prompt_assets.rs#L20-L47","documentation":"A UTF-8 validation guard in the non-dynamic get_prompt: rust_embed returns the embedded prompt file's raw bytes and std::str::from_utf8 panics via expect if those bytes are not valid UTF-8. The input at fault is the compiled-in asset under src/prompts — this fires at runtime only because a non-text file (binary, Latin-1, or a bad merge artifact) was placed in the prompts folder and got embedded into the binary.","triggerScenarios":"Thrown at crates/edit_prediction_cli/src/prompt_assets.rs:38 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Validate every file in src/prompts is valid UTF-8 in a build script or CI check before embedding","Use from_utf8 with error reporting naming the offending file rather than expect","Document that the prompts folder accepts only UTF-8 text templates"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}