{"record":{"id":"81704da8ceb65cb0","repo":"zed-industries/zed","slug":"failed-to-create-username-regex","errorCode":null,"errorMessage":"Failed to create USERNAME_REGEX","messagePattern":"Failed to create USERNAME_REGEX","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/git/src/remote.rs","lineNumber":17,"sourceCode":"use std::str::FromStr;\nuse std::sync::LazyLock;\n\nuse derive_more::Deref;\nuse regex::Regex;\nuse url::Url;\n\n/// The URL to a Git remote.\n#[derive(Debug, PartialEq, Eq, Clone, Deref)]\npub struct RemoteUrl(Url);\n\n// Detect the `user@` prefix of an SCP-like remote (e.g. `git@host:path`). The\n// username may contain anything but the `@`/`:`/`/` that delimit the user,\n// host, and path, so match by exclusion rather than an allowlist that misses\n// names like `first.last`.\nstatic USERNAME_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r\"^[^/@:]+@\").expect(\"Failed to create USERNAME_REGEX\"));\n\nimpl FromStr for RemoteUrl {\n    type Err = url::ParseError;\n\n    fn from_str(input: &str) -> Result<Self, Self::Err> {\n        if USERNAME_REGEX.is_match(input) {\n            // Rewrite remote URLs like `git@github.com:user/repo.git` to `ssh://git@github.com/user/repo.git`\n            let ssh_url = format!(\"ssh://{}\", input.replacen(':', \"/\", 1));\n            Ok(RemoteUrl(Url::parse(&ssh_url)?))\n        } else {\n            Ok(RemoteUrl(Url::parse(input)?))\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use pretty_assertions::assert_eq;","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/git/src/remote.rs#L1-L35","documentation":"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.","triggerScenarios":"Thrown at crates/git/src/remote.rs:17 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}