zed-industries/zed · error

Invalid UTF-8

Error message

Invalid UTF-8

What it means

process_path panics converting a zip-prefixed LSP path back to a path because the remaining bytes after the '/zip:' prefix are not valid UTF-8; the language server sent a path that cannot be represented as a Rust string path.

Source

Thrown at crates/project/src/yarn.rs:83

    }

    pub(crate) fn process_path(
        &mut self,
        path: &Path,
        protocol: &str,
        cx: &Context<Self>,
    ) -> Task<Option<(Arc<Path>, Arc<RelPath>)>> {
        let mut is_zip = protocol.eq("zip");

        let path: &Path = if let Some(non_zip_part) = path
            .as_os_str()
            .as_encoded_bytes()
            .strip_prefix("/zip:".as_bytes())
        {
            // typescript-language-server prepends the paths with zip:, which is messy.
            is_zip = true;
            Path::new(OsStr::new(
                std::str::from_utf8(non_zip_part).expect("Invalid UTF-8"),
            ))
        } else {
            path
        };

        let as_virtual = resolve_virtual(path);
        let Some(path) = as_virtual.or_else(|| is_zip.then(|| Arc::from(path))) else {
            return Task::ready(None);
        };
        if let Some(zip_file) = zip_path(&path) {
            let zip_file: Arc<Path> = Arc::from(zip_file);
            cx.spawn(async move |this, cx| {
                let dir = this
                    .read_with(cx, |this, _| {
                        this.temp_dirs
                            .get(&zip_file)
                            .map(|temp| temp.path().to_owned())
                    })

View on GitHub (pinned to f4178619ac)

Solutions

  1. Use PathBuf::from(OsString) via OsStr::from_encoded_bytes_unchecked on supported platforms instead of requiring UTF-8
  2. Return None for non-UTF-8 paths so the buffer is skipped
  3. Log the raw bytes to diagnose the offending language server output
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/project/src/yarn.rs:83 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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