{"id":"d434489fdf9964eb","repo":"BurntSushi/ripgrep","slug":"stdin","errorCode":null,"errorMessage":"<stdin>:{}","messagePattern":"<stdin>:(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/pattern.rs","lineNumber":108,"sourceCode":"    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    })\n}\n\n/// Read patterns from any reader, 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.\n///\n/// Note that this routine uses its own internal buffer, so the caller should\n/// not provide their own buffered reader if possible.\n///\n/// # Example\n///\n/// This shows how to parse patterns, one per line.\n///\n/// ```\n/// use grep_cli::patterns_from_reader;","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/BurntSushi/ripgrep/blob/3fce3b5bb0236da2df6d99672afb8a719642eca7/crates/cli/src/pattern.rs#L90-L126","documentation":"In patterns_from_stdin, any error from patterns_from_reader (a line that is not valid UTF-8) is wrapped as format!(\"<stdin>:{}\", err). The '<stdin>' label identifies the source as standard input rather than a file path, preserving the file:line convention used elsewhere.","triggerScenarios":"Piping binary or non-UTF-8 data into a tool that reads patterns via patterns_from_stdin (e.g. rg -f - with a pattern list on stdin), where one input line fails pattern_from_bytes UTF-8 validation.","commonSituations":"cat binaryfile | rg -f -; a shell heredoc feeding patterns that contains a stray high byte; cross-platform line-ending issues from a redirected file.","solutions":["Ensure the data piped to stdin is valid UTF-8, one pattern per line.","Filter the stream through iconv -f latin1 -t utf-8 or tr to strip non-UTF-8 bytes before it reaches the tool.","Pass patterns via a file or --regex argument instead of stdin if the source is inherently binary."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match patterns_from_stdin() {\n    Ok(v) => v,\n    Err(e) => { eprintln!(\"{e}\"); vec![] }\n}","preventionTips":["Pipe only valid UTF-8 to pattern-reading stdin modes.","Filter stdin through iconv/tr when the source may be non-UTF-8.","Prefer a patterns file or --regex argument for inherently binary sources."],"tags":["pattern","utf-8","stdin","cli"],"analyzedSha":"3fce3b5bb0236da2df6d99672afb8a719642eca7","analyzedAt":"2026-08-06T01:39:05.073Z","schemaVersion":2}