{"record":{"id":"6306deea0809186b","repo":"gleam-lang/gleam","slug":"failed-regex-to-match-consecutive-underscores","errorCode":null,"errorMessage":"failed regex to match consecutive underscores","messagePattern":"failed regex to match consecutive underscores","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-cli/src/new.rs","lineNumber":416,"sourceCode":"            Some(format!(\"{invalid_name}_app\"))\n        }\n        InvalidProjectNameReason::GleamReservedWord => Some(format!(\"{invalid_name}_app\")),\n        InvalidProjectNameReason::GleamReservedModule => {\n            if invalid_name == \"gleam\" {\n                Some(\"app_gleam\".into())\n            } else {\n                Some(format!(\"{invalid_name}_app\"))\n            }\n        }\n        InvalidProjectNameReason::FormatNotLowercase => Some(invalid_name.to_lowercase()),\n        InvalidProjectNameReason::Format => {\n            let suggestion = regex::Regex::new(r\"[^a-z0-9]\")\n                .expect(\"failed regex to match any non-lowercase and non-alphanumeric characters\")\n                .replace_all(&invalid_name.to_lowercase(), \"_\")\n                .to_string();\n\n            let suggestion = regex::Regex::new(r\"_+\")\n                .expect(\"failed regex to match consecutive underscores\")\n                .replace_all(&suggestion, \"_\")\n                .to_string();\n\n            match validate_name(&suggestion) {\n                Ok(_) => Some(suggestion),\n                Err(_) => None,\n            }\n        }\n    }\n}\n\nfn get_valid_project_name(\n    provided_name: Option<&str>,\n    project_root: &str,\n    confirm: impl Fn(&str) -> Result<bool, Error>,\n) -> Result<ProjectName, Error> {\n    let initial_name = match provided_name {\n        Some(name) => name.trim().to_string(),","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-cli/src/new.rs#L398-L434","documentation":"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.","triggerScenarios":"`gleam new` suggestion path for a Format-invalid name, in a build where regex compilation of the fixed pattern fails — normally unreachable.","commonSituations":"Dependency/build issues with the regex crate, exotic targets, corrupted binaries.","solutions":["Rebuild or update gleam","Update the regex dependency if needed","File an issue with reproduce steps and platform info"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn collapse_underscores(s: &str) -> String {\n    let mut out = String::new();\n    let mut prev_us = false;\n    for c in s.chars() {\n        if c == '_' { if !prev_us { out.push(c); } prev_us = true; }\n        else { out.push(c); prev_us = false; }\n    }\n    out\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid consecutive separators in project names","Keep regex dependency healthy","Validate names before invoking gleam new","Treat this panic as a build bug"],"tags":["regex","panic","internal","project-name"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"15b07c783065c92bb016b1b74ed0995a5259850f","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}