zed-industries/zed · error
Failed to create USERNAME_REGEX
Error message
Failed to create USERNAME_REGEX
What it means
A static-initialization guard: USERNAME_REGEX is a LazyLock holding a hardcoded regex ('^[^/@:]+@') for detecting the user@ prefix of SCP-like git remotes. Regex::new on this constant can only fail if the pattern string itself is malformed — a programming error committed in source — so the expect is an invariant on a compile-time constant, not a reaction to any runtime URL input.
Source
Thrown at crates/git/src/remote.rs:17
use std::str::FromStr;
use std::sync::LazyLock;
use derive_more::Deref;
use regex::Regex;
use url::Url;
/// The URL to a Git remote.
#[derive(Debug, PartialEq, Eq, Clone, Deref)]
pub struct RemoteUrl(Url);
// Detect the `user@` prefix of an SCP-like remote (e.g. `git@host:path`). The
// username may contain anything but the `@`/`:`/`/` that delimit the user,
// host, and path, so match by exclusion rather than an allowlist that misses
// names like `first.last`.
static USERNAME_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[^/@:]+@").expect("Failed to create USERNAME_REGEX"));
impl FromStr for RemoteUrl {
type Err = url::ParseError;
fn from_str(input: &str) -> Result<Self, Self::Err> {
if USERNAME_REGEX.is_match(input) {
// Rewrite remote URLs like `git@github.com:user/repo.git` to `ssh://git@github.com/user/repo.git`
let ssh_url = format!("ssh://{}", input.replacen(':', "/", 1));
Ok(RemoteUrl(Url::parse(&ssh_url)?))
} else {
Ok(RemoteUrl(Url::parse(input)?))
}
}
}
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;View on GitHub (pinned to f4178619ac)
Solutions
- Add a unit test that forces the LazyLock to initialize, turning a bad pattern into a CI failure
- Keep expect but document next to it that the pattern is exercised by a test, so future edits update both
- Compile the pattern once in a build-time check if a regex macro is available
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/git/src/remote.rs:17 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20).
Data as JSON: /api/errors/81704da8ceb65cb0.
Report an issue: GitHub.