{"record":{"id":"65b42fb1a396dff7","repo":"gleam-lang/gleam","slug":"is-gleam-path-re-regex","errorCode":null,"errorMessage":"is_gleam_path() RE regex","messagePattern":"is_gleam_path\\(\\) RE regex","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-cli/src/fs.rs","lineNumber":437,"sourceCode":"        .map_err(|error| Error::FileIo {\n            action: FileIoAction::WriteTo,\n            kind: FileKind::File,\n            path: path.clone(),\n            err: Some(error.to_string()),\n        })\n}\n\nstatic IS_GLEAM_PATH_PATTERN: OnceLock<Regex> = OnceLock::new();\n\nfn is_gleam_path(path: &Utf8Path, dir: impl AsRef<Utf8Path>) -> bool {\n    IS_GLEAM_PATH_PATTERN\n        .get_or_init(|| {\n            Regex::new(&format!(\n                \"^({module}{slash})*{module}\\\\.gleam$\",\n                module = \"[a-z][_a-z0-9]*\",\n                slash = \"(/|\\\\\\\\)\",\n            ))\n            .expect(\"is_gleam_path() RE regex\")\n        })\n        .is_match(\n            path.strip_prefix(dir.as_ref())\n                .expect(\"is_gleam_path(): strip_prefix\")\n                .as_str(),\n        )\n}\n\nfn is_gleam_build_dir(e: &ignore::DirEntry) -> bool {\n    if !e.path().is_dir() || !e.path().ends_with(\"build\") {\n        return false;\n    }\n\n    let Some(parent_path) = e.path().parent() else {\n        return false;\n    };\n\n    parent_path.join(\"gleam.toml\").exists()","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-cli/src/fs.rs#L419-L455","documentation":"A panic raised when compiling the internal regex `^([a-z][_a-z0-9]*(/|\\\\))*[a-z][_a-z0-9]*\\.gleam$` used by `is_gleam_path` to decide whether a file is a Gleam module. The pattern is a compile-time constant, so `Regex::new` failing indicates an internal bug or an incompatible `regex` crate version — never user input.","triggerScenarios":"Calling any API that walks Gleam source files (`gleam_files`, and therefore builds, dependency resolution, etc.) where the statically-built regex fails to compile — essentially only from a bad dependency build or tampered crate source.","commonSituations":"A broken `regex` dependency resolved in the dependency graph, a patched/forked gleam codebase where the pattern string was edited incorrectly, or exotic `regex` feature flags that change accepted syntax.","solutions":["Run `cargo update` / restore the locked dependency versions so a known-good `regex` crate is compiled in.","If you modified the regex pattern string, validate it with `Regex::new(pattern)` in a test or via a regex debugger (e.g. regex101) and fix the syntax.","Rebuild from a clean checkout (`cargo clean && cargo build`) to rule out stale/broken incremental artifacts.","File an issue upstream with the regex crate version if it reproduces with vanilla sources."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// sanity-check the regex crate at build time in your own code\nlet _ = regex::Regex::new(\"^([a-z][_a-z0-9]*/)*[a-z][_a-z0-9]*\\\\.gleam$\").unwrap();","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| gleam_files(&dir).collect::<Vec<_>>())\n    .map_err(|_| anyhow!(\"gleam source scan panicked; check regex dependency\"))?","preventionTips":["Commit and respect Cargo.lock so a known-good `regex` version is used.","Never hand-edit constant regex strings without a unit test that compiles them.","Run `cargo audit`/`cargo update` deliberately and rebuild cleanly after dependency changes.","Treat any occurrence as a bug report for the gleam project, not a user mistake."],"tags":["regex","internal-bug","panic","rust"],"backgroundTag":"internal-invariant-violation","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"}