{"id":"493dfd78d2f7769c","repo":"BurntSushi/ripgrep","slug":"pattern-given-is-not-valid-utf-8","errorCode":null,"errorMessage":"pattern given is not valid UTF-8","messagePattern":"pattern given is not valid UTF-8","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/core/flags/hiargs.rs","lineNumber":1039,"sourceCode":"        // search and neither -e/--regexp nor -f/--file is given. Basically,\n        // the first positional is a pattern only when a pattern hasn't been\n        // given in some other way.\n\n        // No search means no patterns. Even if -e/--regexp or -f/--file is\n        // given, we know we won't use them so don't bother collecting them.\n        if !matches!(low.mode, Mode::Search(_)) {\n            return Ok(Patterns { patterns: vec![] });\n        }\n        // If we got nothing from -e/--regexp and -f/--file, then the first\n        // positional is a pattern.\n        if low.patterns.is_empty() {\n            anyhow::ensure!(\n                !low.positional.is_empty(),\n                \"ripgrep requires at least one pattern to execute a search\"\n            );\n            let ospat = low.positional.remove(0);\n            let Ok(pat) = ospat.into_string() else {\n                anyhow::bail!(\"pattern given is not valid UTF-8\")\n            };\n            return Ok(Patterns { patterns: vec![pat] });\n        }\n        // Otherwise, we need to slurp up our patterns from -e/--regexp and\n        // -f/--file. We de-duplicate as we go. If we don't de-duplicate,\n        // then it can actually lead to major slow downs for sloppy inputs.\n        // This might be surprising, and the regex engine will eventually\n        // de-duplicate duplicative branches in a single regex (maybe), but\n        // not until after it has gone through parsing and some other layers.\n        // If there are a lot of duplicates, then that can lead to a sizeable\n        // extra cost. It is lamentable that we pay the extra cost here to\n        // de-duplicate for a likely uncommon case, but I've seen this have a\n        // big impact on real world data.\n        let mut seen = HashSet::new();\n        let mut patterns = Vec::with_capacity(low.patterns.len());\n        let mut add = |pat: String| {\n            if !seen.contains(&pat) {\n                seen.insert(pat.clone());","sourceCodeStart":1021,"sourceCodeEnd":1057,"githubUrl":"https://github.com/BurntSushi/ripgrep/blob/3fce3b5bb0236da2df6d99672afb8a719642eca7/crates/core/flags/hiargs.rs#L1021-L1057","documentation":"Error \"pattern given is not valid UTF-8\" thrown in BurntSushi/ripgrep.","triggerScenarios":"Thrown at crates/core/flags/hiargs.rs:1039 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the pattern is valid UTF-8","Use escape sequences or --encoding to supply non-UTF-8 patterns"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"3fce3b5bb0236da2df6d99672afb8a719642eca7","analyzedAt":"2026-08-06T01:39:05.073Z","schemaVersion":2}