Skip to content

Commit 6dd64b2

Browse files
committed
refactor: replace .unwrap() with .expect() on infallible calls
The four .unwrap() calls all sit on values that cannot fail in practice (regex literals known at compile time, and a serde_json value built from a json! literal). Switch to .expect() so the panic message documents the invariant if it ever does fire.
1 parent 08f33fe commit 6dd64b2

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl Default for ReactionTiming {
145145
// --- loading ---
146146

147147
fn expand_env_vars(raw: &str) -> String {
148-
let re = Regex::new(r"\$\{(\w+)\}").unwrap();
148+
let re = Regex::new(r"\$\{(\w+)\}").expect("env var regex literal is valid");
149149
re.replace_all(raw, |caps: &regex::Captures| {
150150
std::env::var(&caps[1]).unwrap_or_default()
151151
})

src/discord.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ impl EventHandler for Handler {
115115
});
116116
let prompt_with_sender = format!(
117117
"<sender_context>\n{}\n</sender_context>\n\n{}",
118-
serde_json::to_string(&sender_ctx).unwrap(),
118+
serde_json::to_string(&sender_ctx)
119+
.expect("sender_ctx is built from a serde_json::json! literal and cannot fail to serialize"),
119120
prompt
120121
);
121122

@@ -500,7 +501,7 @@ fn compose_display(tool_lines: &[String], text: &str) -> String {
500501
}
501502

502503
static MENTION_RE: LazyLock<regex::Regex> = LazyLock::new(|| {
503-
regex::Regex::new(r"<@[!&]?\d+>").unwrap()
504+
regex::Regex::new(r"<@[!&]?\d+>").expect("mention regex literal is valid")
504505
});
505506

506507
fn strip_mention(content: &str) -> String {
@@ -509,7 +510,8 @@ fn strip_mention(content: &str) -> String {
509510

510511
fn shorten_thread_name(prompt: &str) -> String {
511512
// Shorten GitHub URLs: https://github.com/owner/repo/issues/123 → owner/repo#123
512-
let re = regex::Regex::new(r"https?://github\.com/([^/]+/[^/]+)/(issues|pull)/(\d+)").unwrap();
513+
let re = regex::Regex::new(r"https?://github\.com/([^/]+/[^/]+)/(issues|pull)/(\d+)")
514+
.expect("github url regex literal is valid");
513515
let shortened = re.replace_all(prompt, "$1#$3");
514516
let name: String = shortened.chars().take(40).collect();
515517
if name.len() < shortened.len() {

0 commit comments

Comments
 (0)