gleam-lang/gleam · error
failed regex to match any non-lowercase and…
Error message
failed regex to match any non-lowercase and non-alphanumeric characters
What it means
In suggest_valid_name (InvalidProjectNameReason::Format branch), the regex [^a-z0-9] used to replace invalid characters with underscores is compiled with an .expect panic. Like the other new.rs regexes, the constant pattern is always valid, so this panic signals a regex-engine internal failure rather than bad input.
Solutions
- Rebuild/update gleam — this is a build/dependency problem, not a naming problem
- Update the regex crate in Cargo.lock if a regression exists
- Report to Gleam maintainers with platform details if reproducible
Defensive patterns
Strategy: validation
Validate before calling
fn suggestion_charset_ok(s: &str) -> bool {
s.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_')
} Prevention
- Use names matching [a-z][a-z0-9_]* from the start
- Avoid symbols/unicode in project names
- Rebuild if constant regexes panic
- Sanitize names in scripts that call gleam new
When it happens
Trigger: `gleam new` with a name that has invalid format, triggering the suggestion path, in a build where the regex crate cannot compile the fixed pattern — normally unreachable.
Common situations: Broken dependency builds, unusual targets, or binary corruption. Users with invalid names should otherwise receive a suggestion or a normal InvalidProjectName error.
Related errors
- failed regex to match consecutive underscores
- failed regex to match valid but non-lowercase name format
- 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/7caf33c743282701.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-cli/src/new.rs:411
}
_ => None,
},
InvalidProjectNameReason::ErlangReservedWord => Some(format!("{invalid_name}_app")),
InvalidProjectNameReason::ErlangStandardLibraryModule => {
Some(format!("{invalid_name}_app"))
}
InvalidProjectNameReason::GleamReservedWord => Some(format!("{invalid_name}_app")),
InvalidProjectNameReason::GleamReservedModule => {
if invalid_name == "gleam" {
Some("app_gleam".into())
} else {
Some(format!("{invalid_name}_app"))
}
}
InvalidProjectNameReason::FormatNotLowercase => Some(invalid_name.to_lowercase()),
InvalidProjectNameReason::Format => {
let suggestion = regex::Regex::new(r"[^a-z0-9]")
.expect("failed regex to match any non-lowercase and non-alphanumeric characters")
.replace_all(&invalid_name.to_lowercase(), "_")
.to_string();
let suggestion = regex::Regex::new(r"_+")
.expect("failed regex to match consecutive underscores")
.replace_all(&suggestion, "_")
.to_string();
match validate_name(&suggestion) {
Ok(_) => Some(suggestion),
Err(_) => None,
}
}
}
}
fn get_valid_project_name(
provided_name: Option<&str>,View on GitHub (pinned to 15b07c7830)