zed-industries/zed · error

Path is not valid utf-8: {:?}

Error message

Path is not valid utf-8: {:?}

What it means

AbsPath::new rejected the input because the path contains bytes that are not valid UTF-8 (to_str returned None). AbsPath requires valid UTF-8 by design, so non-UTF-8 paths from the OS cannot be represented; the raw path is printed via Debug.

Source

Thrown at crates/path/src/abs_path.rs:26

};

use anyhow::Context;

use crate::{PathStyle, rel_path::RelPath};

// An absolute path on the user's local filesystem.
// Requires paths to be valid utf-8
#[derive(PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
#[repr(transparent)]
pub struct AbsPath(Path);

impl AbsPath {
    pub fn new(path: &Path) -> anyhow::Result<&Self> {
        if !path.is_absolute() {
            return Err(anyhow::anyhow!("Path is not absolute: {:?}", path));
        }
        if path.to_str().is_none() {
            return Err(anyhow::anyhow!("Path is not valid utf-8: {:?}", path));
        }
        Ok(Self::new_unchecked(path))
    }

    fn new_unchecked(path: &Path) -> &Self {
        // SAFETY: `AbsPath` is a `repr(transparent)` wrapper around `Path`.
        unsafe { &*(path as *const Path as *const Self) }
    }

    pub fn to_abs_path_buf(&self) -> AbsPathBuf {
        AbsPathBuf(self.0.to_owned())
    }

    pub fn join(&self, name: impl AsRef<str>) -> AbsPathBuf {
        AbsPathBuf(self.0.join(name.as_ref()))
    }

    pub fn join_rel_path(&self, relative_path: &RelPath) -> AbsPathBuf {

View on GitHub (pinned to f4178619ac)

Solutions

  1. Find the source of the non-UTF-8 path (often a file created with a legacy locale encoding) and rename it to a UTF-8 name
  2. If the path comes from config or user input, validate/normalize the encoding before use
  3. On Unix, convert using to_string_lossy only if losing bytes is acceptable for the use case
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/path/src/abs_path.rs:26 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/1349d6d02755971b. Report an issue: GitHub.