Kuberwastaken/claurst · info
(?:https?|ftp)://\S+|www\.\S+
Error message
(?:https?|ftp)://\S+|www\.\S+
What it means
This panic wraps construction of the static URL-detection regex used by the /links command: `regex::Regex::new(r"(?:https?|ftp)://\S+|www\.\S+").expect(...)`. The pattern is a compile-time constant and is valid, so the expect should never fire; it exists because Regex::new returns a Result that must be handled inside the Lazy initializer.
Solutions
- If this panic occurred, the pattern string in `links_url_regex` was modified — revert or fix the regex syntax.
- Validate regex changes in a test (`Regex::new(PATTERN).unwrap()` in a unit test) so breakage is caught by `cargo test`, not at runtime.
- Prefer `once_cell::sync::Lazy` with a checked pattern plus a debug_assert, or move validation to a compile-time check.
- Keep the error message distinct (`"links URL regex"`) so the panicking constant is easy to locate.
Example fix
// before
static URL_RE: once_cell::sync::Lazy<regex::Regex> = once_cell::sync::Lazy::new(|| {
regex::Regex::new(r"(?:https?|ftp)://\S+|www\.\S+").expect("links URL regex")
});
// after (test guarding the constant)
#[test]
fn links_url_regex_is_valid() {
links_url_regex();
} Defensive patterns
Strategy: validation
Validate before calling
// Compile-time-ish guard: unit test asserting the constant parses
#[test]
fn links_url_regex_compiles() {
regex::Regex::new(r"(?:https?|ftp)://\S+|www\.\S+").unwrap();
} Prevention
- Never edit the regex constant without running the regex-compiles unit test
- Keep the descriptive expect message so the failing constant is identifiable
- Validate regex syntax locally with `regex-cli` or a quick `Regex::new` snippet before committing
When it happens
Trigger: Practically unreachable: calling `links_url_regex()` (via `extract_session_urls`) only panics if the hard-coded regex string was edited into an invalid pattern, since the Lazy static is built on first use.
Common situations: A developer edits the URL pattern and introduces a syntax error (unbalanced group, bad escape); the panic then fires on the first /links invocation rather than at compile time.
Related errors
- failed to build reqwest client
- generationConfig must be an object
- Failed to build reqwest client
- valid OAuth authorize base URL
- voice thread runtime
AI-assisted analysis of Kuberwastaken/claurst@b0637c97ec (2026-09-10).
Data as JSON: /api/errors/7a9cb52fedd15d33.
Report an issue: GitHub.
Appendix: source
Thrown at src-rust/crates/commands/src/share.rs:145
} else if opted_out {
"The gist is secret (unlisted). Anyone with the link can view it; delete the gist to revoke access."
} else {
"Could not auto-open the link. Copy the URL above. The gist is secret (unlisted); delete the gist to revoke access."
};
CommandResult::Message(format!(
"Share URL: {viewer}\nGist: {gist_url}\n\n{footer}"
))
}
}
// ---- /links --------------------------------------------------------------
/// Detect URLs in plain text. Mirrors the styling regex in tui::messages::markdown
/// so the user sees the same links the renderer highlights.
fn links_url_regex() -> &'static regex::Regex {
static URL_RE: once_cell::sync::Lazy<regex::Regex> = once_cell::sync::Lazy::new(|| {
regex::Regex::new(r"(?:https?|ftp)://\S+|www\.\S+").expect("links URL regex")
});
&URL_RE
}
fn strip_trailing_punct(url: &str) -> String {
let mut s = url.to_string();
while let Some(c) = s.chars().last() {
if matches!(c, '.' | ',' | ';' | ':' | '!' | '?' | ')' | ']' | '}' | '\'' | '"' | '>') {
s.pop();
} else {
break;
}
}
s
}
/// Walk messages (oldest → newest), pulling text out of each block and
/// returning unique URLs in *most-recent-first* order.
View on GitHub (pinned to b0637c97ec)