pemistahl/grex · error

No test cases have been provided for regular expression…

Error message

No test cases have been provided for regular expression generation

What it means

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.

Solutions

  1. Check test cases for emptiness before calling from(), and return a domain error or use a default regex instead
  2. Fix the upstream source so it always yields at least one non-empty example string
  3. If empty input is legitimate, skip regex construction entirely rather than calling the builder

Example fix

// before
let builder = RegExpBuilder::from(&test_cases);
// after
assert!(!test_cases.is_empty(), "need at least one test case");
let builder = RegExpBuilder::from(&test_cases);
Defensive patterns

Strategy: validation

Validate before calling

if test_cases.is_empty() { return Err(anyhow!("no test cases supplied for regex generation")); }

Try / catch

let result = std::panic::catch_unwind(|| RegExpBuilder::from(&cases));
match result { Ok(b) => b, Err(_) => fallback_regex() }

Prevention

When it happens

Trigger: Calling RegExpBuilder::from(&[]) or from(&Vec::new()) — any empty slice of strings that should serve as example test cases.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of pemistahl/grex@99cc347707 (2026-09-13). Data as JSON: /api/errors/8b43342f1ff1accf. Report an issue: GitHub.

Appendix: source

Thrown at src/builder.rs:48

    "Minimum substring length must be greater than zero";

/// This struct builds regular expressions from user-provided test cases.
#[derive(Clone)]
#[cfg_attr(feature = "python", pyo3::prelude::pyclass)]
pub struct RegExpBuilder {
    pub(crate) test_cases: Vec<String>,
    pub(crate) config: RegExpConfig,
}

impl RegExpBuilder {
    /// Specifies the test cases to build the regular expression from.
    ///
    /// The test cases need not be sorted because `RegExpBuilder` sorts them internally.
    ///
    /// ⚠ Panics if `test_cases` is empty.
    pub fn from<T: Clone + Into<String>>(test_cases: &[T]) -> Self {
        if test_cases.is_empty() {
            panic!("{}", MISSING_TEST_CASES_MESSAGE);
        }
        Self {
            test_cases: test_cases.iter().cloned().map(|it| it.into()).collect_vec(),
            config: RegExpConfig::new(),
        }
    }

    /// Specifies a text file containing test cases to build the regular expression from.
    ///
    /// The test cases need not be sorted because `RegExpBuilder` sorts them internally.
    ///
    /// Each test case needs to be on a separate line.
    /// Lines may be ended with either a newline (`\n`) or
    /// a carriage return with a line feed (`\r\n`).
    /// The final line ending is optional.
    ///
    /// ⚠ Panics if:
    /// - the file cannot be found

View on GitHub (pinned to 99cc347707)