{"record":{"id":"51f5dbb517a9fd34","repo":"pemistahl/grex","slug":"the-specified-file-could-not-be-found","errorCode":null,"errorMessage":"The specified file could not be found","messagePattern":"The specified file could not be found","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/builder.rs","lineNumber":76,"sourceCode":"    /// The test cases need not be sorted because `RegExpBuilder` sorts them internally.\n    ///\n    /// Each test case needs to be on a separate line.\n    /// Lines may be ended with either a newline (`\\n`) or\n    /// a carriage return with a line feed (`\\r\\n`).\n    /// The final line ending is optional.\n    ///\n    /// ⚠ Panics if:\n    /// - the file cannot be found\n    /// - the file's encoding is not valid UTF-8 data\n    /// - the file cannot be opened because of conflicting permissions\n    pub fn from_file<T: Into<PathBuf>>(file_path: T) -> Self {\n        match std::fs::read_to_string(file_path.into()) {\n            Ok(file_content) => Self {\n                test_cases: file_content.lines().map(|it| it.to_string()).collect_vec(),\n                config: RegExpConfig::new(),\n            },\n            Err(error) => match error.kind() {\n                ErrorKind::NotFound => panic!(\"The specified file could not be found\"),\n                ErrorKind::InvalidData => {\n                    panic!(\"The specified file's encoding is not valid UTF-8\")\n                }\n                ErrorKind::PermissionDenied => {\n                    panic!(\"Permission denied: The specified file could not be opened\")\n                }\n                _ => panic!(\"{}\", error),\n            },\n        }\n    }\n\n    /// Converts any Unicode decimal digit to character class `\\d`.\n    ///\n    /// This method takes precedence over\n    /// [`with_conversion_of_words`](Self::with_conversion_of_words) if both are set.\n    /// Decimal digits are converted to `\\d`, the remaining word characters to `\\w`.\n    ///\n    /// This method takes precedence over","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/pemistahl/grex/blob/99cc347707375e00514f938b76d885a201dfc110/src/builder.rs#L58-L94","documentation":"RegExpBuilder::from_file reads the file at file_path with std::fs::read_to_string; on an io::Error of kind NotFound it panics with 'The specified file could not be found'. The builder treats a missing file path as unrecoverable for its purpose and aborts instead of constructing an empty builder.","triggerScenarios":"Calling RegExpBuilder::from_file(\"missing.txt\") (or any PathBuf that does not exist on disk) — including typos in the path, wrong working directory, or a file deleted before the call.","commonSituations":"Running the binary from a different cwd than expected so a relative path no longer resolves; passing a path from config/CLI that was never validated; the file lives in a packaged container without being copied in.","solutions":["Verify the path exists (std::path::Path::exists) before calling from_file","Fix typos in the path and prefer absolute paths or paths anchored to an env-provided base directory","Read the file yourself with std::fs::read_to_string and handle the NotFound error, then pass the lines to RegExpBuilder::from"],"exampleFix":"// before\nlet builder = RegExpBuilder::from_file(\"data/examples.txt\");\n// after\nlet path = Path::new(\"data/examples.txt\");\nassert!(path.exists(), \"examples file not found: {}\", path.display());\nlet builder = RegExpBuilder::from_file(path);","handlingStrategy":"validation","validationCode":"let path = Path::new(file_path);\nif !path.exists() { return Err(anyhow!(\"examples file not found: {}\", path.display())); }","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| RegExpBuilder::from_file(&path))\n    .map_err(|_| format!(\"could not read examples file: {}\", path.display()))","preventionTips":["Resolve relative paths against an explicit base directory, not the process cwd","Probe with Path::exists (or File::open) before calling from_file","Log the absolute path in errors to expose cwd-related mistakes"],"tags":["panic","io","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"99cc347707375e00514f938b76d885a201dfc110","analyzedAt":"2026-09-13T15:42:56.144Z","contentChangedAt":"2026-09-13T15:42:56.144Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}