{"record":{"id":"f190cac164f060ee","repo":"zed-industries/zed","slug":"failed-to-parse-example-file-error","errorCode":null,"errorMessage":"Failed to parse example file: {}\n{error}","messagePattern":"Failed to parse example file: (.+?)\n(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/edit_prediction_cli/src/example.rs","lineNumber":243,"sourceCode":"            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;\n                }\n                examples.push(example);\n            }\n            \"jsonl\" => examples.extend(\n                content\n                    .lines()\n                    .enumerate()\n                    .map(|(line_ix, line)| {\n                        let mut example =\n                            serde_json::from_str::<Example>(line).unwrap_or_else(|error| {\n                                panic!(\n                                    \"Failed to parse example on {}:{}\\n{error}\",\n                                    path.display(),\n                                    line_ix + 1\n                                )","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/edit_prediction_cli/src/example.rs#L225-L261","documentation":"For .json inputs the loader does serde_json::from_str::<Example> on the whole file and panics with the serde error when it does not match the Example schema — missing required fields, wrong field types, or trailing content after the object. The message names the file and includes the underlying parse error.","triggerScenarios":"A JSON object missing required spec fields; wrong field types (string where a number is expected); two concatenated objects in one file; a line-delimited file misnamed .json instead of .jsonl.","commonSituations":"Hand-edited examples dropping a key; schema drift after a CLI version bump; exports that are actually JSONL with the wrong extension.","solutions":["Read the {error} in the panic — serde names the exact missing field or type mismatch","Rename genuinely line-delimited files to .jsonl so each line parses as one Example","Validate the file against the Example struct with a small serde program before batching","Regenerate the example from a known-good one"],"exampleFix":"# before — bad.json\n{\"inputs\": \"fn main() {}\"}   // panic: Failed to parse example file: bad.json (missing field `spec`)\n\n# after — bad.json\n{\"spec\": {\"name\": \"rename\", \"language\": \"rust\"}, \"inputs\": \"fn main() {}\"}","handlingStrategy":"validation","validationCode":"use std::fs;\n\nfn validate_example_file(path: &std::path::Path) -> Result<(), String> {\n    let content = fs::read_to_string(path).map_err(|e| e.to_string())?;\n    serde_json::from_str::<Example>(&content).map(|_| ()).map_err(|e| e.to_string())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Dry-run-parse each .json against the Example schema before batching","Name line-delimited files .jsonl, single-object files .json","Regenerate examples from known-good fixtures rather than hand-editing"],"tags":["json","serde","schema","panic","edit-prediction"],"backgroundTag":"json-parse-error","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"}