{"id":"b9ffb5d41a84a797","repo":"BurntSushi/ripgrep","slug":"error-b9ffb5","errorCode":null,"errorMessage":"{}: {}","messagePattern":"\\{\\}: \\{\\}","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/pattern.rs","lineNumber":85,"sourceCode":"pub fn pattern_from_bytes(\n    pattern: &[u8],\n) -> Result<&str, InvalidPatternError> {\n    std::str::from_utf8(pattern).map_err(|err| InvalidPatternError {\n        original: escape(pattern),\n        valid_up_to: err.valid_up_to(),\n    })\n}\n\n/// Read patterns from a file path, one per line.\n///\n/// If there was a problem reading or if any of the patterns contain invalid\n/// UTF-8, then an error is returned. If there was a problem with a specific\n/// pattern, then the error message will include the line number and the file\n/// path.\npub fn patterns_from_path<P: AsRef<Path>>(path: P) -> io::Result<Vec<String>> {\n    let path = path.as_ref();\n    let file = std::fs::File::open(path).map_err(|err| {\n        io::Error::new(\n            io::ErrorKind::Other,\n            format!(\"{}: {}\", path.display(), err),\n        )\n    })?;\n    patterns_from_reader(file).map_err(|err| {\n        io::Error::new(\n            io::ErrorKind::Other,\n            format!(\"{}:{}\", path.display(), err),\n        )\n    })\n}\n\n/// Read patterns from stdin, one per line.\n///\n/// If there was a problem reading or if any of the patterns contain invalid\n/// UTF-8, then an error is returned. If there was a problem with a specific\n/// pattern, then the error message will include the line number and the fact\n/// that it came from stdin.","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/BurntSushi/ripgrep/blob/3fce3b5bb0236da2df6d99672afb8a719642eca7/crates/cli/src/pattern.rs#L67-L103","documentation":"In patterns_from_path, the call to std::fs::File::open(path) is wrapped so the IO error is prefixed with the file path: format!(\"{}: {}\", path.display(), err). This is a user-facing message format, not a distinct error type — it annotates *which* patterns file could not be opened and why.","triggerScenarios":"Calling patterns_from_path with a path that does not exist, is unreadable (permissions), or names a directory rather than a file, causing File::open to fail.","commonSituations":"rg -f missingfile; --patterns-file pointing at a typo'd path; running in a directory where the patterns file is chmod 000; CI checking out a repo without the referenced patterns file.","solutions":["Verify the path exists and is a readable regular file before passing it.","Fix typos or relative-path issues (run from the expected working directory, or use an absolute path).","Correct file permissions (chmod +r) so the process can open it."],"exampleFix":"// before\nlet pats = patterns_from_path(\"missing.txt\")?;\n\n// after\nlet path = \"patterns.txt\";\nassert!(std::fs::metadata(path).is_ok(), \"patterns file missing\");\nlet pats = patterns_from_path(path)?;","handlingStrategy":"validation","validationCode":"fn readable_patterns_file(p: &std::path::Path) -> bool {\n    std::fs::metadata(p).map(|m| m.is_file()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"let pats = patterns_from_path(path);\nif let Err(e) = pats { eprintln!(\"{e}\"); return; }","preventionTips":["Check the path exists and is readable before calling patterns_from_path.","Use absolute paths or assert the working directory in CLI tools.","Surface the file path in errors so users can locate the missing file."],"tags":["pattern","io","file-not-found","cli"],"analyzedSha":"3fce3b5bb0236da2df6d99672afb8a719642eca7","analyzedAt":"2026-08-06T01:39:05.073Z","schemaVersion":2}