gleam-lang/gleam · error
failed regex to match consecutive underscores
Error message
failed regex to match consecutive underscores
What it means
Second suggestion step in suggest_valid_name: regex _+ collapses consecutive underscores after character replacement, compiled with .expect("failed regex to match consecutive underscores"). Same family as 84-86: the constant pattern is always valid, so the panic is an internal invariant violation only reachable if the regex engine fails.
Solutions
- Rebuild or update gleam
- Update the regex dependency if needed
- File an issue with reproduce steps and platform info
Defensive patterns
Strategy: validation
Validate before calling
fn collapse_underscores(s: &str) -> String {
let mut out = String::new();
let mut prev_us = false;
for c in s.chars() {
if c == '_' { if !prev_us { out.push(c); } prev_us = true; }
else { out.push(c); prev_us = false; }
}
out
} Prevention
- Avoid consecutive separators in project names
- Keep regex dependency healthy
- Validate names before invoking gleam new
- Treat this panic as a build bug
When it happens
Trigger: `gleam new` suggestion path for a Format-invalid name, in a build where regex compilation of the fixed pattern fails — normally unreachable.
Common situations: Dependency/build issues with the regex crate, exotic targets, corrupted binaries.
Related errors
- failed regex to match any non-lowercase and…
- 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/6306deea0809186b.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-cli/src/new.rs:416
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>,
project_root: &str,
confirm: impl Fn(&str) -> Result<bool, Error>,
) -> Result<ProjectName, Error> {
let initial_name = match provided_name {
Some(name) => name.trim().to_string(),View on GitHub (pinned to 15b07c7830)