pemistahl/grex · error
Quantity of minimum repetitions must be greater than zero
Error message
Quantity of minimum repetitions must be greater than zero
What it means
RegExpBuilder::with_minimum_repetitions panics with MINIMUM_REPETITIONS_MESSAGE when quantity is 0. A minimum repetition count of zero would make the 'repeat at least n times' conversion meaningless, so the configuration API rejects it eagerly. The default, if unset, is 1.
Solutions
- Pass a quantity >= 1; omit the call entirely to use the default of 1
- Clamp the input (quantity.max(1)) before calling the method
- Validate the config/CLI value at parse time and reject 0 with a clear user-facing error
Example fix
// before builder.with_minimum_repetitions(min_reps); // min_reps may be 0 // after let min_reps = min_reps.max(1); builder.with_minimum_repetitions(min_reps);
Defensive patterns
Strategy: validation
Validate before calling
if min_reps == 0 { return Err(anyhow!("--min-reps must be >= 1")); }
builder.with_minimum_repetitions(min_reps); Try / catch
let b = std::panic::catch_unwind(|| { let mut b = RegExpBuilder::from(&cases); b.with_minimum_repetitions(q); b })
.map_err(|_| "minimum repetitions must be > 0".to_string()); Prevention
- Clamp parsed numeric config with .max(1) before applying it
- Reject zero at the CLI/config parsing layer with a user-facing message
- Remember the default is 1 — omit the call when you do not need a custom value
When it happens
Trigger: Calling builder.with_minimum_repetitions(0), typically because the value came from an unvalidated CLI flag, config file, or arithmetic expression that underflowed.
Common situations: A --min-reps CLI argument defaulted to 0; parsing user config where an empty/absent value became 0; subtracting values and hitting zero.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Minimum substring length must be greater than zero
- No test cases have been provided for regular expression…
- The specified file could not be found
- The specified file's encoding is not valid UTF-8
- Permission denied: The specified file could not be opened
AI-assisted analysis of pemistahl/grex@99cc347707 (2026-09-13).
Data as JSON: /api/errors/44e68bc21cc339df.
Report an issue: GitHub.
Appendix: source
Thrown at src/builder.rs:188
self.config.is_case_insensitive_matching = true;
self
}
/// Replaces non-capturing groups with capturing ones.
pub fn with_capturing_groups(&mut self) -> &mut Self {
self.config.is_capturing_group_enabled = true;
self
}
/// Specifies the minimum quantity of substring repetitions to be converted if
/// [`with_conversion_of_repetitions`](Self::with_conversion_of_repetitions) is set.
///
/// If the quantity is not explicitly set with this method, a default value of 1 will be used.
///
/// ⚠ Panics if `quantity` is zero.
pub fn with_minimum_repetitions(&mut self, quantity: u32) -> &mut Self {
if quantity == 0 {
panic!("{}", MINIMUM_REPETITIONS_MESSAGE);
}
self.config.minimum_repetitions = quantity;
self
}
/// Specifies the minimum length a repeated substring must have in order to be converted if
/// [`with_conversion_of_repetitions`](Self::with_conversion_of_repetitions) is set.
///
/// If the length is not explicitly set with this method, a default value of 1 will be used.
///
/// ⚠ Panics if `length` is zero.
pub fn with_minimum_substring_length(&mut self, length: u32) -> &mut Self {
if length == 0 {
panic!("{}", MINIMUM_SUBSTRING_LENGTH_MESSAGE);
}
self.config.minimum_substring_length = length;
self
}View on GitHub (pinned to 99cc347707)