gleam-lang/gleam · error

is_gleam_path() RE regex

Error message

is_gleam_path() RE regex

What it means

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.

Solutions

  1. Run `cargo update` / restore the locked dependency versions so a known-good `regex` crate is compiled in.
  2. 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.
  3. Rebuild from a clean checkout (`cargo clean && cargo build`) to rule out stale/broken incremental artifacts.
  4. File an issue upstream with the regex crate version if it reproduces with vanilla sources.
Defensive patterns

Strategy: fallback

Validate before calling

// sanity-check the regex crate at build time in your own code
let _ = regex::Regex::new("^([a-z][_a-z0-9]*/)*[a-z][_a-z0-9]*\\.gleam$").unwrap();

Try / catch

std::panic::catch_unwind(|| gleam_files(&dir).collect::<Vec<_>>())
    .map_err(|_| anyhow!("gleam source scan panicked; check regex dependency"))?

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14). Data as JSON: /api/errors/65b42fb1a396dff7. Report an issue: GitHub.

Appendix: source

Thrown at compiler-cli/src/fs.rs:437

        .map_err(|error| Error::FileIo {
            action: FileIoAction::WriteTo,
            kind: FileKind::File,
            path: path.clone(),
            err: Some(error.to_string()),
        })
}

static IS_GLEAM_PATH_PATTERN: OnceLock<Regex> = OnceLock::new();

fn is_gleam_path(path: &Utf8Path, dir: impl AsRef<Utf8Path>) -> bool {
    IS_GLEAM_PATH_PATTERN
        .get_or_init(|| {
            Regex::new(&format!(
                "^({module}{slash})*{module}\\.gleam$",
                module = "[a-z][_a-z0-9]*",
                slash = "(/|\\\\)",
            ))
            .expect("is_gleam_path() RE regex")
        })
        .is_match(
            path.strip_prefix(dir.as_ref())
                .expect("is_gleam_path(): strip_prefix")
                .as_str(),
        )
}

fn is_gleam_build_dir(e: &ignore::DirEntry) -> bool {
    if !e.path().is_dir() || !e.path().ends_with("build") {
        return false;
    }

    let Some(parent_path) = e.path().parent() else {
        return false;
    };

    parent_path.join("gleam.toml").exists()

View on GitHub (pinned to 15b07c7830)