Skip to content

Commit fdec4e4

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 df911c1 commit fdec4e4

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
@@ -143,7 +143,7 @@ impl Default for ReactionTiming {
143143
// --- loading ---
144144

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

src/discord.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ impl EventHandler for Handler {
8888
});
8989
let prompt_with_sender = format!(
9090
"<sender_context>\n{}\n</sender_context>\n\n{}",
91-
serde_json::to_string(&sender_ctx).unwrap(),
91+
serde_json::to_string(&sender_ctx)
92+
.expect("sender_ctx is built from a serde_json::json! literal and cannot fail to serialize"),
9293
prompt
9394
);
9495

@@ -331,13 +332,14 @@ fn compose_display(tool_lines: &[String], text: &str) -> String {
331332
}
332333

333334
fn strip_mention(content: &str) -> String {
334-
let re = regex::Regex::new(r"<@[!&]?\d+>").unwrap();
335+
let re = regex::Regex::new(r"<@[!&]?\d+>").expect("mention regex literal is valid");
335336
re.replace_all(content, "").trim().to_string()
336337
}
337338

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

0 commit comments

Comments
 (0)