{"record":{"id":"8b43342f1ff1accf","repo":"pemistahl/grex","slug":"no-test-cases-have-been-provided-for-regular-expression","errorCode":null,"errorMessage":"No test cases have been provided for regular expression generation","messagePattern":"No test cases have been provided for regular expression generation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/builder.rs","lineNumber":48,"sourceCode":"    \"Minimum substring length must be greater than zero\";\n\n/// This struct builds regular expressions from user-provided test cases.\n#[derive(Clone)]\n#[cfg_attr(feature = \"python\", pyo3::prelude::pyclass)]\npub struct RegExpBuilder {\n    pub(crate) test_cases: Vec<String>,\n    pub(crate) config: RegExpConfig,\n}\n\nimpl RegExpBuilder {\n    /// Specifies the test cases to build the regular expression from.\n    ///\n    /// The test cases need not be sorted because `RegExpBuilder` sorts them internally.\n    ///\n    /// ⚠ Panics if `test_cases` is empty.\n    pub fn from<T: Clone + Into<String>>(test_cases: &[T]) -> Self {\n        if test_cases.is_empty() {\n            panic!(\"{}\", MISSING_TEST_CASES_MESSAGE);\n        }\n        Self {\n            test_cases: test_cases.iter().cloned().map(|it| it.into()).collect_vec(),\n            config: RegExpConfig::new(),\n        }\n    }\n\n    /// Specifies a text file containing test cases to build the regular expression from.\n    ///\n    /// 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","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/pemistahl/grex/blob/99cc347707375e00514f938b76d885a201dfc110/src/builder.rs#L30-L66","documentation":"RegExpBuilder::from panics with MISSING_TEST_CASES_MESSAGE when the given slice is empty. The builder cannot infer a regular expression from zero examples, so an empty input is treated as a programmer error and rejected eagerly. The docs explicitly warn that the method panics if test_cases is empty.","triggerScenarios":"Calling RegExpBuilder::from(&[]) or from(&Vec::new()) — any empty slice of strings that should serve as example test cases.","commonSituations":"A data pipeline that usually supplies examples is upstream-failing and yields an empty list; a filter (dedup, trim, split) accidentally removes all entries; config-driven examples loaded from an empty string or empty collection.","solutions":["Check test cases for emptiness before calling from(), and return a domain error or use a default regex instead","Fix the upstream source so it always yields at least one non-empty example string","If empty input is legitimate, skip regex construction entirely rather than calling the builder"],"exampleFix":"// before\nlet builder = RegExpBuilder::from(&test_cases);\n// after\nassert!(!test_cases.is_empty(), \"need at least one test case\");\nlet builder = RegExpBuilder::from(&test_cases);","handlingStrategy":"validation","validationCode":"if test_cases.is_empty() { return Err(anyhow!(\"no test cases supplied for regex generation\")); }","typeGuard":null,"tryCatchPattern":"let result = std::panic::catch_unwind(|| RegExpBuilder::from(&cases));\nmatch result { Ok(b) => b, Err(_) => fallback_regex() }","preventionTips":["Assert non-empty input at the boundary where examples are collected","Provide a default regex or early-return when the example source yields nothing","Add a unit test covering the empty-input path of your example loader"],"tags":["panic","empty-input","regex-builder"],"backgroundTag":"empty-required-field","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"}