{"record":{"id":"d6b72f7c7131e03e","repo":"zed-industries/zed","slug":"failed-to-read-path-path","errorCode":null,"errorMessage":"Failed to read path: {path:?}","messagePattern":"Failed to read path: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/edit_prediction_cli/src/example.rs","lineNumber":228,"sourceCode":"            .join(self.owner.as_ref())\n            .join(self.name.as_ref())\n    }\n}\n\npub fn read_example_files(inputs: &[PathBuf]) -> Vec<Example> {\n    let mut examples = Vec::new();\n\n    for path in inputs {\n        let is_stdin = path.as_path() == Path::new(\"-\");\n        let content = if is_stdin {\n            let mut buffer = String::new();\n            std::io::stdin()\n                .read_to_string(&mut buffer)\n                .expect(\"Failed to read from stdin\");\n            buffer\n        } else {\n            std::fs::read_to_string(path)\n                .unwrap_or_else(|_| panic!(\"Failed to read path: {path:?}\"))\n        };\n        let filename = path.file_stem().unwrap().to_string_lossy().to_string();\n        let ext = if !is_stdin {\n            path.extension()\n                .map(|ext| ext.to_string_lossy().to_string())\n                .unwrap_or_else(|| panic!(\"{} should have an extension\", path.display()))\n        } else {\n            \"jsonl\".to_string()\n        };\n\n        match ext.as_ref() {\n            \"json\" => {\n                let mut example =\n                    serde_json::from_str::<Example>(&content).unwrap_or_else(|error| {\n                        panic!(\"Failed to parse example file: {}\\n{error}\", path.display())\n                    });\n                if example.spec.name.is_empty() {\n                    example.spec.name = filename;","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/edit_prediction_cli/src/example.rs#L210-L246","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typos in hand-written paths; files on detached or unmounted network drives; non-UTF-8 exports renamed to .json; glob characters quoted by mistake.","solutions":["Check the path exists and is a readable regular file before passing it","Re-encode non-UTF-8 files: iconv -f UTF-16 -t UTF-8 input > output","Pipe via stdin when generating input on the fly: cat file | edit-prediction-cli eval -","Inspect glob expansion in scripts so unmatched patterns do not reach the CLI"],"exampleFix":"# before\nedit-prediction-cli eval mystery.jsonl   # panic: Failed to read path: \"mystery.jsonl\"\n\n# after\nls mystery.jsonl || echo \"typo?\"\niconv -f UTF-16 -t UTF-8 data.jsonl | edit-prediction-cli eval -","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\np = Path(path)\nassert p.is_file(), f\"{p} is not a readable file\"\np.read_text(encoding=\"utf-8\")  # raises now, before the CLI panics","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate input paths (exists, is a file) before passing them to the CLI","Normalize encodings to UTF-8 upstream with iconv or a preprocessor","Use '-' and stdin for generated input instead of temp files"],"tags":["file-io","utf-8","cli","panic","edit-prediction"],"backgroundTag":"file-read-failed","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}