gleam-lang/gleam · error
failed regex to match valid but non-lowercase name format
Error message
failed regex to match valid but non-lowercase name format
What it means
Same pattern as the lowercase check: the mixed-case regex ^[a-zA-Z][a-zA-Z0-9_]*$ in validate_name is compiled with .expect("failed regex to match valid but non-lowercase name format"). A panic here is an internal invariant violation, since the constant pattern is always valid. It exists to distinguish 'valid name but wrong case' from 'invalid format' when reporting InvalidProjectName.
Solutions
- Rebuild or update gleam to the latest version
- Inspect/update the regex dependency if a regression is suspected
- File a Gleam issue with platform and build details if reproducible
Defensive patterns
Strategy: validation
Validate before calling
fn is_valid_but_not_lowercase(name: &str) -> bool {
let c0 = name.chars().next();
c0.map_or(false, |c| c.is_ascii_alphabetic())
&& name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')
&& name.chars().any(|c| c.is_ascii_uppercase())
} Prevention
- Prefer lowercase names to avoid the non-lowercase path entirely
- Keep gleam builds reproducible and dependencies fresh
- Report constant-regex panics upstream
- Use the CLI suggestion when offered instead of crafting names
When it happens
Trigger: Called during validate_name (via suggest_valid_name or get_valid_project_name, e.g. `gleam new MyProject`) only if the regex engine fails to compile the fixed pattern — not caused by user input.
Common situations: Same as error 84: broken regex crate build, exotic target with insufficient stack, corrupted binary. Normally unreachable.
Related errors
- failed regex to match any non-lowercase and…
- failed regex to match consecutive underscores
- failed regex to match valid name format
- Index out of bounds
- is_gleam_path() RE regex
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/0b849f5b5227a66d.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-cli/src/new.rs:369
reason: InvalidProjectNameReason::ErlangStandardLibraryModule,
})
} else if parse::lexer::string_to_keyword(name).is_some() {
Err(Error::InvalidProjectName {
name: name.to_string(),
reason: InvalidProjectNameReason::GleamReservedWord,
})
} else if name == "gleam" {
Err(Error::InvalidProjectName {
name: name.to_string(),
reason: InvalidProjectNameReason::GleamReservedModule,
})
} else if regex::Regex::new("^[a-z][a-z0-9_]*$")
.expect("failed regex to match valid name format")
.is_match(name)
{
Ok(())
} else if regex::Regex::new("^[a-zA-Z][a-zA-Z0-9_]*$")
.expect("failed regex to match valid but non-lowercase name format")
.is_match(name)
{
Err(Error::InvalidProjectName {
name: name.to_string(),
reason: InvalidProjectNameReason::FormatNotLowercase,
})
} else {
Err(Error::InvalidProjectName {
name: name.to_string(),
reason: InvalidProjectNameReason::Format,
})
}
}
fn suggest_valid_name(invalid_name: &str, reason: &InvalidProjectNameReason) -> Option<String> {
match reason {
InvalidProjectNameReason::GleamPrefix => match invalid_name.strip_prefix("gleam_") {
Some(stripped) if invalid_name != "gleam_" => {View on GitHub (pinned to 15b07c7830)