zed-industries/zed · error

prompt file is not valid UTF-8

Error message

prompt file is not valid UTF-8

What it means

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.

Source

Thrown at crates/edit_prediction_cli/src/prompt_assets.rs:38

        .context(name)
        .expect("Failed to read prompt");
    let leaked = contents.leak();
    PROMPT_CACHE.write().unwrap().insert(name, leaked);
    return Cow::Borrowed(leaked);
}

#[cfg(not(feature = "dynamic_prompts"))]
pub fn get_prompt(name: &'static str) -> Cow<'static, str> {
    use rust_embed::RustEmbed;

    #[derive(RustEmbed)]
    #[folder = "src/prompts"]
    struct EmbeddedPrompts;

    match EmbeddedPrompts::get(name) {
        Some(file) => match file.data {
            Cow::Borrowed(bytes) => {
                Cow::Borrowed(std::str::from_utf8(bytes).expect("prompt file is not valid UTF-8"))
            }
            Cow::Owned(bytes) => {
                Cow::Owned(String::from_utf8(bytes).expect("prompt file is not valid UTF-8"))
            }
        },
        None => panic!("prompt file not found: {name}"),
    }
}

View on GitHub (pinned to f4178619ac)

Solutions

  1. Validate every file in src/prompts is valid UTF-8 in a build script or CI check before embedding
  2. Use from_utf8 with error reporting naming the offending file rather than expect
  3. Document that the prompts folder accepts only UTF-8 text templates
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/edit_prediction_cli/src/prompt_assets.rs:38 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/51bbe08208e855ec. Report an issue: GitHub.