{"record":{"id":"3ed5bb4f122dbf50","repo":"pemistahl/grex","slug":"minimum-substring-length-must-be-greater-than-zero","errorCode":null,"errorMessage":"Minimum substring length must be greater than zero","messagePattern":"Minimum substring length must be greater than zero","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/builder.rs","lineNumber":202,"sourceCode":"    ///\n    /// ⚠ Panics if `quantity` is zero.\n    pub fn with_minimum_repetitions(&mut self, quantity: u32) -> &mut Self {\n        if quantity == 0 {\n            panic!(\"{}\", MINIMUM_REPETITIONS_MESSAGE);\n        }\n        self.config.minimum_repetitions = quantity;\n        self\n    }\n\n    /// Specifies the minimum length a repeated substring must have in order to be converted if\n    /// [`with_conversion_of_repetitions`](Self::with_conversion_of_repetitions) is set.\n    ///\n    /// If the length is not explicitly set with this method, a default value of 1 will be used.\n    ///\n    /// ⚠ Panics if `length` is zero.\n    pub fn with_minimum_substring_length(&mut self, length: u32) -> &mut Self {\n        if length == 0 {\n            panic!(\"{}\", MINIMUM_SUBSTRING_LENGTH_MESSAGE);\n        }\n        self.config.minimum_substring_length = length;\n        self\n    }\n\n    /// Converts non-ASCII characters to unicode escape sequences.\n    /// The parameter `use_surrogate_pairs` specifies whether to convert astral code planes\n    /// (range `U+010000` to `U+10FFFF`) to surrogate pairs.\n    pub fn with_escaping_of_non_ascii_chars(&mut self, use_surrogate_pairs: bool) -> &mut Self {\n        self.config.is_non_ascii_char_escaped = true;\n        self.config.is_astral_code_point_converted_to_surrogate = use_surrogate_pairs;\n        self\n    }\n\n    /// Produces a nicer looking regular expression in verbose mode.\n    pub fn with_verbose_mode(&mut self) -> &mut Self {\n        self.config.is_verbose_mode_enabled = true;\n        self","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/pemistahl/grex/blob/99cc347707375e00514f938b76d885a201dfc110/src/builder.rs#L184-L220","documentation":"RegExpBuilder::with_minimum_substring_length panics with MINIMUM_SUBSTRING_LENGTH_MESSAGE when length is 0. Substrings of length zero are meaningless for the repeated-substring conversion, so zero is rejected eagerly. The default, if unset, is 1.","triggerScenarios":"Calling builder.with_minimum_substring_length(0), usually from an unvalidated CLI flag or config value that defaulted to zero.","commonSituations":"An optional config key like min_substring_length absent from the file and parsed as 0; a compute expression evaluating to zero; user typing --min-length 0.","solutions":["Pass a length >= 1; omit the call entirely to use the default of 1","Clamp the input (length.max(1)) before calling the method","Validate the config/CLI value at parse time and reject 0 with a clear user-facing error"],"exampleFix":"// before\nbuilder.with_minimum_substring_length(min_len); // min_len may be 0\n// after\nlet min_len = min_len.max(1);\nbuilder.with_minimum_substring_length(min_len);","handlingStrategy":"validation","validationCode":"if min_len == 0 { return Err(anyhow!(\"--min-length must be >= 1\")); }\nbuilder.with_minimum_substring_length(min_len);","typeGuard":null,"tryCatchPattern":"let b = std::panic::catch_unwind(|| { let mut b = RegExpBuilder::from(&cases); b.with_minimum_substring_length(l); b })\n    .map_err(|_| \"minimum substring length must be > 0\".to_string());","preventionTips":["Clamp parsed numeric config with .max(1) before applying it","Treat absent config keys as 'use default', not 0","Add a deserializer default (#[serde(default = \"one\")]) for such options"],"tags":["panic","config","validation"],"backgroundTag":"invalid-config-value","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"}