fix: replace .unwrap() with .expect() on infallible calls#168
Open
arhtur007 wants to merge 1 commit intoopenabdev:mainfrom
Open
fix: replace .unwrap() with .expect() on infallible calls#168arhtur007 wants to merge 1 commit intoopenabdev:mainfrom
arhtur007 wants to merge 1 commit intoopenabdev:mainfrom
Conversation
masami-agent
approved these changes
Apr 10, 2026
Contributor
masami-agent
left a comment
There was a problem hiding this comment.
LGTM — straightforward improvement. All four sites are infallible (compile-time regex literals and json! macro output), so .expect() with a reason string is the idiomatic Rust convention here. Good housekeeping 👍
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.
fdec4e4 to
6dd64b2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replace four
.unwrap()calls with.expect("...")so the panic message documents the invariant.Changes
src/config.rs—expand_env_varsregex literalsrc/discord.rs—sender_ctxJSON serialization,strip_mentionregex,shorten_thread_nameGitHub URL regexRationale
All four call sites are infallible in practice (regex literals known at compile time, and a
serde_json::Valuebuilt from ajson!macro)..expect("reason")is the conventional formfor "should never panic" — if it ever does fire, the message points at the violated invariant.
.unwrap_or_else()is not suitable here because there is no meaningful fallback value for an invalid regex or a failed serialization — the program cannot continue correctly, so a panicwith a descriptive message is the right behavior.