zed-industries/zed · error

Failed to read path: {path:?}

Error message

Failed to read path: {path:?}

What it means

edit_prediction_cli's example loader reads each input path (or stdin when the path is '-') as UTF-8 text via std::fs::read_to_string. Any read failure — missing file, directory passed as file, permission denied, non-UTF-8 bytes — hits unwrap_or_else with this panic naming the path. Inputs are a CLI precondition: they must exist and be valid UTF-8.

Source

Thrown at crates/edit_prediction_cli/src/example.rs:228

            .join(self.owner.as_ref())
            .join(self.name.as_ref())
    }
}

pub fn read_example_files(inputs: &[PathBuf]) -> Vec<Example> {
    let mut examples = Vec::new();

    for path in inputs {
        let is_stdin = path.as_path() == Path::new("-");
        let content = if is_stdin {
            let mut buffer = String::new();
            std::io::stdin()
                .read_to_string(&mut buffer)
                .expect("Failed to read from stdin");
            buffer
        } else {
            std::fs::read_to_string(path)
                .unwrap_or_else(|_| panic!("Failed to read path: {path:?}"))
        };
        let filename = path.file_stem().unwrap().to_string_lossy().to_string();
        let ext = if !is_stdin {
            path.extension()
                .map(|ext| ext.to_string_lossy().to_string())
                .unwrap_or_else(|| panic!("{} should have an extension", path.display()))
        } else {
            "jsonl".to_string()
        };

        match ext.as_ref() {
            "json" => {
                let mut example =
                    serde_json::from_str::<Example>(&content).unwrap_or_else(|error| {
                        panic!("Failed to parse example file: {}\n{error}", path.display())
                    });
                if example.spec.name.is_empty() {
                    example.spec.name = filename;

View on GitHub (pinned to f4178619ac)

Solutions

  1. Check the path exists and is a readable regular file before passing it
  2. Re-encode non-UTF-8 files: iconv -f UTF-16 -t UTF-8 input > output
  3. Pipe via stdin when generating input on the fly: cat file | edit-prediction-cli eval -
  4. Inspect glob expansion in scripts so unmatched patterns do not reach the CLI

Example fix

# before
edit-prediction-cli eval mystery.jsonl   # panic: Failed to read path: "mystery.jsonl"

# after
ls mystery.jsonl || echo "typo?"
iconv -f UTF-16 -t UTF-8 data.jsonl | edit-prediction-cli eval -
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

p = Path(path)
assert p.is_file(), f"{p} is not a readable file"
p.read_text(encoding="utf-8")  # raises now, before the CLI panics

Prevention

When it happens

Trigger: Passing a path that does not exist; passing a directory; a file encoded as UTF-16 or Latin-1 (common for logs and Windows exports); unreadable permissions; an unmatched shell glob passed through as a literal string.

Common situations: Typos in hand-written paths; files on detached or unmounted network drives; non-UTF-8 exports renamed to .json; glob characters quoted by mistake.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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