{"record":{"id":"21240d73abbdd976","repo":"Zackriya-Solutions/meetily","slug":"invalid-regex-pattern","errorCode":null,"errorMessage":"Invalid regex pattern","messagePattern":"Invalid regex pattern","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"frontend/src-tauri/src/ollama/metadata.rs","lineNumber":260,"sourceCode":"                return ctx as usize;\n            }\n        }\n    }\n\n    ULTIMATE_FALLBACK\n}\n\n/// Parse num_ctx parameter from Ollama modelfile\n///\n/// # Arguments\n/// * `modelfile` - The modelfile string from /api/show response\n///\n/// # Returns\n/// Context size in tokens, defaults to 4000 if not found\nfn parse_num_ctx_from_modelfile(modelfile: &str) -> usize {\n    // Regex to match: PARAMETER num_ctx <number>\n    static RE: Lazy<Regex> = Lazy::new(|| {\n        Regex::new(r\"PARAMETER\\s+num_ctx\\s+(\\d+)\").expect(\"Invalid regex pattern\")\n    });\n\n    RE.captures(modelfile)\n        .and_then(|caps| caps.get(1))\n        .and_then(|m| m.as_str().parse::<usize>().ok())\n        .unwrap_or_else(|| {\n            tracing::debug!(\n                \"num_ctx not found in modelfile, using default {}\",\n                ULTIMATE_FALLBACK\n            );\n            ULTIMATE_FALLBACK\n        })\n}\n\n/// Get fallback metadata based on model name pattern matching\n///\n/// # Arguments\n/// * `model_name` - Name of the model","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/Zackriya-Solutions/meetily/blob/0281737d87d26352fb0adc78c8c0975f691b23d1/frontend/src-tauri/src/ollama/metadata.rs#L242-L278","documentation":"Regex::new compiles the hard-coded literal 'PARAMETER\\s+num_ctx\\s+(\\d+)' inside a Lazy static. A fixed, syntactically valid pattern compiles deterministically, so this expect cannot fail at runtime as written; it exists to satisfy the type system and would only fire if someone edits the literal into an invalid regex (unbalanced group, bad escape).","triggerScenarios":"Editing the pattern string incorrectly during maintenance; effectively nothing else — the regex crate's accepted syntax for this pattern is stable across versions.","commonSituations":"Never observed in production; this is the canonical Rust idiom for one-time static regex compilation (e.g. OnceLock/Lazy + expect).","solutions":["No action needed for the current literal","If editing the pattern: validate it on regex101 or add a unit test asserting Regex::new succeeds","For defense in depth, add #[test] fn regex_patterns_compile() that constructs every static regex in the module"],"exampleFix":"// guard against future edits\n#[test]\nfn num_ctx_regex_compiles() {\n    assert!(regex::Regex::new(r\"PARAMETER\\s+num_ctx\\s+(\\d+)\").is_ok());\n}","handlingStrategy":"validation","validationCode":"#[test]\nfn static_regexes_compile() {\n    assert!(regex::Regex::new(r\"PARAMETER\\s+num_ctx\\s+(\\d+)\").is_ok());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat static-regex expects as compile-time facts; add a unit test so edits cannot silently break them","Review any diff that touches regex literals in code review","Prefer regex101 or the regex crate docs to validate new patterns before committing"],"tags":["rust","regex","invariant","ollama","lazy-static"],"backgroundTag":"regex-compile-failed","analyzedSha":"0281737d87d26352fb0adc78c8c0975f691b23d1","analyzedAt":"2026-08-16T20:57:52.567Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}