{"id":"48de277c419cc25c","repo":"BurntSushi/ripgrep","slug":"error-48de27","errorCode":null,"errorMessage":"{}:{}","messagePattern":"\\{\\}:\\{\\}","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/pattern.rs","lineNumber":91,"sourceCode":"    })\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.\npub fn patterns_from_stdin() -> io::Result<Vec<String>> {\n    let stdin = io::stdin();\n    let locked = stdin.lock();\n    patterns_from_reader(locked).map_err(|err| {\n        io::Error::new(io::ErrorKind::Other, format!(\"<stdin>:{}\", err))\n    })","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/BurntSushi/ripgrep/blob/3fce3b5bb0236da2df6d99672afb8a719642eca7/crates/cli/src/pattern.rs#L73-L109","documentation":"In patterns_from_path, after the file is opened successfully, patterns_from_reader is called and any error reading or decoding lines is wrapped as format!(\"{}:{}\", path.display(), err) — note the colon (no space) separator, matching the file:line convention. It tells the user the failure originated inside a specific patterns file.","triggerScenarios":"The patterns file opens fine but a line cannot be decoded as UTF-8 (pattern_from_bytes fails inside patterns_from_reader), producing an inner '<line>: <InvalidPatternError>' that gets prefixed with the file path.","commonSituations":"A patterns file containing one line with invalid UTF-8 bytes; a CRLF/legacy-encoded patterns file; a patterns file corrupted by a bad editor or transfer.","solutions":["Open the patterns file in an editor that highlights invalid UTF-8 and fix or remove the offending line.","Re-save the file as UTF-8 without BOM.","Run iconv or a sanitizer to strip/replace non-UTF-8 bytes before searching."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"fn patterns_file_is_utf8(p: &std::path::Path) -> bool {\n    std::fs::read(p).map(|b| std::str::from_utf8(&b).is_ok()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match patterns_from_path(path) {\n    Ok(v) => v,\n    Err(e) => { eprintln!(\"{e}\"); vec![] }\n}","preventionTips":["Save patterns files as UTF-8 without BOM.","Lint pattern files in CI with a UTF-8 validity check.","Trim trailing whitespace/CRLF from shared pattern files."],"tags":["pattern","utf-8","patterns-file","cli"],"analyzedSha":"3fce3b5bb0236da2df6d99672afb8a719642eca7","analyzedAt":"2026-08-06T01:39:05.073Z","schemaVersion":2}