{"record":{"id":"5ad902d6cc83b026","repo":"zed-industries/zed","slug":"failed-to-read-prompt","errorCode":null,"errorMessage":"Failed to read prompt","messagePattern":"Failed to read prompt","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/edit_prediction_cli/src/prompt_assets.rs","lineNumber":21,"sourceCode":"#[cfg(feature = \"dynamic_prompts\")]\npub fn get_prompt(name: &'static str) -> Cow<'static, str> {\n    use anyhow::Context;\n    use std::collections::HashMap;\n    use std::path::Path;\n    use std::sync::{LazyLock, RwLock};\n\n    const PROMPTS_DIR: &str = concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/src/prompts\");\n\n    static PROMPT_CACHE: LazyLock<RwLock<HashMap<&'static str, &'static str>>> =\n        LazyLock::new(|| RwLock::new(HashMap::default()));\n\n    let filesystem_path = Path::new(PROMPTS_DIR).join(name);\n    if let Some(cached_contents) = PROMPT_CACHE.read().unwrap().get(name) {\n        return Cow::Borrowed(cached_contents);\n    }\n    let contents = std::fs::read_to_string(&filesystem_path)\n        .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            }","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/edit_prediction_cli/src/prompt_assets.rs#L3-L39","documentation":"A guard on the dynamic-prompts path only: when the dynamic_prompts feature is enabled, get_prompt reads the prompt template file from src/prompts/<name> at runtime and this expect fires if fs::read fails — missing prompt file, wrong name, unreadable permissions, or the binary running from a tree where CARGO_MANIFEST_DIR content is absent. The .context(name) wraps the io::Error so the panic names the offending prompt file.","triggerScenarios":"Thrown at crates/edit_prediction_cli/src/prompt_assets.rs:21 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Return Cow<'static, str> from a fallible loader or cache the error and report which prompt file is missing instead of panicking","Fall back to the rust_embed-compiled copy of the prompt when the filesystem read fails","Run tests/builds with the same prompt asset set and validate all prompt names exist at startup"],"exampleFix":null,"handlingStrategy":"fallback","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-14T00:17:10.932Z"}