Zackriya-Solutions/meetily · info

Invalid regex pattern

Error message

Invalid regex pattern

What it means

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).

Source

Thrown at frontend/src-tauri/src/ollama/metadata.rs:260

                return ctx as usize;
            }
        }
    }

    ULTIMATE_FALLBACK
}

/// Parse num_ctx parameter from Ollama modelfile
///
/// # Arguments
/// * `modelfile` - The modelfile string from /api/show response
///
/// # Returns
/// Context size in tokens, defaults to 4000 if not found
fn parse_num_ctx_from_modelfile(modelfile: &str) -> usize {
    // Regex to match: PARAMETER num_ctx <number>
    static RE: Lazy<Regex> = Lazy::new(|| {
        Regex::new(r"PARAMETER\s+num_ctx\s+(\d+)").expect("Invalid regex pattern")
    });

    RE.captures(modelfile)
        .and_then(|caps| caps.get(1))
        .and_then(|m| m.as_str().parse::<usize>().ok())
        .unwrap_or_else(|| {
            tracing::debug!(
                "num_ctx not found in modelfile, using default {}",
                ULTIMATE_FALLBACK
            );
            ULTIMATE_FALLBACK
        })
}

/// Get fallback metadata based on model name pattern matching
///
/// # Arguments
/// * `model_name` - Name of the model

View on GitHub (pinned to 0281737d87)

Solutions

  1. No action needed for the current literal
  2. If editing the pattern: validate it on regex101 or add a unit test asserting Regex::new succeeds
  3. For defense in depth, add #[test] fn regex_patterns_compile() that constructs every static regex in the module

Example fix

// guard against future edits
#[test]
fn num_ctx_regex_compiles() {
    assert!(regex::Regex::new(r"PARAMETER\s+num_ctx\s+(\d+)").is_ok());
}
Defensive patterns

Strategy: validation

Validate before calling

#[test]
fn static_regexes_compile() {
    assert!(regex::Regex::new(r"PARAMETER\s+num_ctx\s+(\d+)").is_ok());
}

Prevention

When it happens

Trigger: Editing the pattern string incorrectly during maintenance; effectively nothing else — the regex crate's accepted syntax for this pattern is stable across versions.

Common situations: Never observed in production; this is the canonical Rust idiom for one-time static regex compilation (e.g. OnceLock/Lazy + expect).

Related errors


AI-assisted analysis of Zackriya-Solutions/meetily@0281737d87 (2026-08-16). Data as JSON: /api/errors/21240d73abbdd976. Report an issue: GitHub.