-
Notifications
You must be signed in to change notification settings - Fork 132
Refactor/error handling #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors error handling throughout the codebase by replacing ad-hoc error strings and unwraps with custom error variants and proper error mapping. Key changes include:
- Consistent usage of .map_err(Error::...) for transforming errors in various modules.
- Removal of direct unwrap calls in favor of error propagation in production-critical code.
- Introduction of a dedicated error module with rich error types for better diagnostics.
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/screen/status.rs | Added error mapping for git status operations. |
| src/screen/show_refs.rs | Refactored remote name retrieval with proper error mapping. |
| src/prompt.rs | Improved terminal error handling via .map_err(Error::Term). |
| src/ops/stash.rs | Converted error strings to custom Error variants in stash operations. |
| src/ops/show.rs | Updated error propagation when launching external editor and creating screens. |
| src/ops/push.rs | Replaced direct branch head retrieval with error-mapped function call. |
| src/ops/pull.rs | Updated branch head and remote configuration error handling. |
| src/ops/log.rs | Improved logging error mapping with custom error wrapping. |
| src/ops/copy_hash.rs | Enhanced clipboard error handling by mapping errors using Error::Clipboard. |
| src/menu/arg.rs | Standardized argument parsing errors using custom Error variants. |
| src/main.rs | Centralized error handling for terminal operations and log file access. |
| src/lib.rs | Updated core error type usage and refactored repo opening and configuration initialization. |
| src/items.rs | Enhanced reflog and revwalk error mapping. |
| src/git2_opts.rs | Refactored git2 options error mapping for improved clarity. |
| src/git/remote.rs | Improved error transformation for branch remote name and upstream configuration. |
| src/git/mod.rs | Refactored diff parsing and branch name retrieval with custom error mapping. |
| src/file_watcher.rs | Added error mapping for file watcher initialization and replaced unwrap with error handling. |
| src/error.rs | Introduced a custom error module with various error types for detailed diagnostics. |
| src/config.rs | Standardized configuration error handling using custom error variants. |
| gitu-diff/src/lib.rs | Minor adjustments to error trait implementations in the diff parser. |
Comments suppressed due to low confidence (3)
src/git/mod.rs:117
- Using unwrap() on the result of .nth(1) may panic if the line does not contain a second element. Consider handling the None case gracefully by returning a proper error or using an alternative approach.
.map(|line| line.split(' ').nth(1).unwrap().to_string()))
src/git/mod.rs:137
- The use of unwrap() when parsing diffs can result in a panic if the diff parsing fails. It is recommended to propagate the error using map_err() instead.
file_diffs: gitu_diff::Parser::new(&text).parse_diff().unwrap(),
src/file_watcher.rs:26
- Using unwrap() on the result of build() for the Gitignore can lead to a runtime panic. Consider handling the error with map_err() to return a controlled error.
.build().unwrap();
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #334 +/- ##
==========================================
- Coverage 87.57% 86.65% -0.93%
==========================================
Files 65 66 +1
Lines 5965 6098 +133
==========================================
+ Hits 5224 5284 +60
- Misses 741 814 +73 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
No description provided.