refactor: handle errors instead of panicking with unwrap in non-test code#619
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #619 +/- ##
==========================================
- Coverage 75.35% 74.43% -0.93%
==========================================
Files 31 31
Lines 2447 2394 -53
==========================================
- Hits 1844 1782 -62
- Misses 603 612 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…code Replaces every .unwrap() in non-test code with proper error handling so that failures surface as human-readable errors instead of panics: - Sources (repo/gist/releases): move the fallible 'from' and 'recovery' parsing into the stream so parse errors propagate through the Result stream instead of unwrapping. - Releases: replace error-check-then-unwrap patterns with match expressions. - Pairing engine: convert tokio JoinError from completed backup tasks into a human_errors::Error instead of unwrapping. - Add a HumanizableError impl for tokio::task::JoinError.
2cec733 to
f3a497b
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.
Summary
Removes every
.unwrap()from non-test code, replacing each with proper error handling so failures surface as human-readable errors instead of panics. The remaining.unwrap()calls are all inside#[cfg(test)]modules.Changes
src/sources/github_repo.rs&src/sources/github_gist.rs: Moved the falliblefromandrecoveryparsing inside thetry_stream!block so parse errors propagate through theResultstream via?instead of unwrapping. The recovery-mode parse now uses amatchthat returns the default when unset and yields the parse error otherwise.src/sources/github_releases.rs: Moved the target parse into thestream!block (yielding the error and returning on failure), and replaced twoif let Err(...) { … } … .unwrap()patterns withmatchexpressions.src/pairing.rs: Replacedjoin_next().await.unwrap().unwrap()andfut.unwrap()withmatcharms that yield task results and convert atokio::task::JoinError(from a panicked/cancelled backup task) into ahuman_errors::Error.src/errors.rs: Added aHumanizableErrorimplementation fortokio::task::JoinError, following the existing pattern.Testing
cargo check --all-targetspasses.cargo testpasses for all 151 tests, except one pre-existing live-network integration test (get_releases::case_1) that hit a GitHub API rate limit (403). Notably, the refactor correctly propagated that 403 as a proper error through the stream rather than panicking internally.