{"id":"1ec86465bafa6509","repo":"rust-lang/cargo","slug":"err","errorCode":null,"errorMessage":"{err}","messagePattern":"\\{err\\}","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_new.rs","lineNumber":665,"sourceCode":"    }\n\n    /// `format_existing` is used to format the `IgnoreList` when the ignore file\n    /// already exists. It reads the contents of the given `BufRead` and\n    /// checks if the contents of the ignore list are already existing in the\n    /// file.\n    fn format_existing<T: BufRead>(&self, existing: T, vcs: VersionControl) -> CargoResult<String> {\n        let mut existing_items = Vec::new();\n        for (i, item) in existing.lines().enumerate() {\n            match item {\n                Ok(s) => existing_items.push(s),\n                Err(err) => match err.kind() {\n                    ErrorKind::InvalidData => {\n                        return Err(anyhow!(\n                            \"Character at line {} is invalid. Cargo only supports UTF-8.\",\n                            i\n                        ));\n                    }\n                    _ => return Err(anyhow!(err)),\n                },\n            }\n        }\n\n        let ignore_items = match vcs {\n            VersionControl::Hg => &self.hg_ignore,\n            VersionControl::Fossil => &self.fossil_ignore,\n            _ => &self.ignore,\n        };\n\n        let mut out = String::new();\n\n        // Fossil does not support `#` comments.\n        if vcs != VersionControl::Fossil {\n            out.push_str(\"\\n\\n# Added by cargo\\n\");\n            if ignore_items\n                .iter()\n                .any(|item| existing_items.contains(item))","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_new.rs#L647-L683","documentation":"Catch-all IO error while reading lines of an existing ignore file in IgnoreList::format_existing. The InvalidData (non-UTF-8) case is handled separately (error 114); any other io::Error kind (permission denied, disk I/O, broken pipe, etc.) is wrapped and re-thrown here. The {err} is the original std::io::Error Display.","triggerScenarios":"`cargo new`/`cargo init` where the existing `.gitignore`/`.hgignore`/`.ignore` exists but cannot be read due to permission errors, the file being a dangling symlink, a read error mid-file, or the path being a directory.","commonSituations":"File mode 000 owned by another user; broken symlink in a partially-restored backup; NFS/SMB hiccup mid-read; .gitignore is accidentally a directory; read-only filesystem mounts.","solutions":["Check permissions: `ls -l .gitignore` and `chmod`/`chown` as needed","Fix or remove dangling symlinks: `ls -la` and `rm` the broken link","Verify the path is a regular file and not a directory","Retry after resolving the underlying filesystem/IO issue"],"exampleFix":"# before: .gitignore unreadable (mode 000)\ncargo init   # -> io error\n# after\nchmod 644 .gitignore\ncargo init","handlingStrategy":"try-catch","validationCode":"use std::path::Path;\nfn ensure_ignore_readable(path: &Path) -> std::io::Result<()> {\n    let meta = std::fs::metadata(path)?;\n    if !meta.is_file() { return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, \"not a regular file\")); }\n    std::fs::File::open(path)?.read_to_end(&mut Vec::new())?;\n    Ok(())\n}\n\nensure_ignore_readable(Path::new(\".gitignore\"))?;","typeGuard":"import { statSync, accessSync, constants } from 'fs';\nfunction isReadableFile(path: string): boolean {\n  try { const s = statSync(path); return s.isFile() && accessSync(path, constants.R_OK) === undefined; }\n  catch { return false; }\n}","tryCatchPattern":"match std::fs::read_to_string(ignore_path) {\n    Ok(content) => { /* proceed */ }\n    Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => {\n        eprintln!(\"fix permissions on {} then retry\", ignore_path.display());\n        return Err(e.into());\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Ensure ignore files are regular files with read permission (mode 0644)","Resolve dangling symlinks before `cargo init`","Verify filesystem health (df, fsck) when transient IO errors appear"],"tags":["vcs","io","ignore-file","filesystem"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}