{"record":{"id":"b5ca91197d3eac9c","repo":"rust-lang/rust","slug":"path-e","errorCode":null,"errorMessage":"{path}: {e}","messagePattern":"\\{path\\}: \\{e\\}","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/tools/rustfmt/src/formatting.rs","lineNumber":304,"sourceCode":"        psess: &ParseSess,\n        path: FileName,\n        result: String,\n        report: &mut FormatReport,\n    ) -> Result<(), ErrorKind> {\n        if let Some(ref mut out) = self.out {\n            match source_file::write_file(\n                Some(psess),\n                &path,\n                &result,\n                out,\n                &mut *self.emitter,\n                self.config.newline_style(),\n            ) {\n                Ok(ref result) if result.has_diff => report.add_diff(),\n                Err(e) => {\n                    // Create a new error with path_str to help users see which files failed\n                    let err_msg = format!(\"{path}: {e}\");\n                    return Err(io::Error::new(e.kind(), err_msg).into());\n                }\n                _ => {}\n            }\n        }\n\n        self.source_file.push((path, result));\n        Ok(())\n    }\n}\n\npub(crate) struct FormattingError {\n    pub(crate) line: usize,\n    pub(crate) kind: ErrorKind,\n    is_comment: bool,\n    is_string: bool,\n    pub(crate) line_buffer: String,\n}\n","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/rustfmt/src/formatting.rs#L286-L322","documentation":"This is a recoverable io::Error produced by rustfmt's Session::handle_formatted_file (formatting.rs:304). When source_file::write_file fails (reading the original file or emitting formatted output), rustfmt wraps the underlying io::Error with the offending file path as \"{path}: {e}\" while preserving the original ErrorKind. Unlike the rustc entries below, this is a returned Err, not a panic.","triggerScenarios":"Calling rustfmt as a library via Session::format_* / handle_formatted_file, or running the rustfmt binary, when write_file returns Err: fs::read_to_string fails (file missing, unreadable, permission denied) or the output Write sink fails (broken pipe, disk full, closed sink).","commonSituations":"Piping rustfmt output to a command that exits early (e.g. `rustfmt foo.rs | head` -> BrokenPipe), formatting a non-existent or read-only path, a full disk, or a custom Write implementor in library use that returns Err.","solutions":["Read the path appended in the message to identify the failing file, then verify it exists and is readable (fix permissions / restore the file).","If piping output, stop the downstream reader from closing early, or write to a file / std::io::sink() instead of a pipe.","In library use, match on the returned Result<(), ErrorKind> and branch on ErrorKind (NotFound, PermissionDenied, BrokenPipe, WriteZero) for targeted recovery.","Check available disk space and that the output target is writable."],"exampleFix":"// before\nlet report = session.format(input)?; // error text is \"{path}: {e}\"\n\n// after\nmatch session.format(input) {\n    Ok(report) => { /* ... */ }\n    Err(ErrorKind::Io(e)) => {\n        eprintln!(\"rustfmt failed on {:?}: {} (kind={:?})\", path, e, e.kind());\n    }\n    Err(other) => return Err(other.into()),\n}","handlingStrategy":"try-catch","validationCode":"use std::path::Path;\nfn can_format(path: &Path) -> bool {\n    path.exists() && path.metadata().map(|m| !m.permissions().readonly()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match session.format(input) {\n    Ok(report) => { /* apply report */ }\n    Err(ErrorKind::Io(e)) => {\n        // message is \"{path}: {e}\"; e.kind() tells you NotFound/PermissionDenied/BrokenPipe\n        log::warn!(\"rustfmt skipped {:?}: {e}\", path);\n    }\n    Err(other) => return Err(other.into()),\n}","preventionTips":["Validate the input path exists and is readable before handing it to rustfmt.","Avoid piping rustfmt output to readers that may close early; prefer a file sink or std::io::sink() in tests.","In library use, always match the returned Result and branch on ErrorKind rather than unwrap().","Ensure adequate disk space and writable output targets in CI."],"tags":["rustfmt","io","rust"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}