Skip to content

refactor: improve error handling with custom AppError and anyhow#22

Merged
AsfhtgkDavid merged 7 commits intoAsfhtgkDavid:mainfrom
AliyaRazyapova:feature/improve-error-handling
Feb 27, 2026
Merged

refactor: improve error handling with custom AppError and anyhow#22
AsfhtgkDavid merged 7 commits intoAsfhtgkDavid:mainfrom
AliyaRazyapova:feature/improve-error-handling

Conversation

@AliyaRazyapova
Copy link
Contributor

Description

This PR overhauls error handling in the project by replacing all instances of .unwrap() and .expect() in production code with idiomatic Rust error propagation using the ? operator and a custom error type. The goal is to eliminate unexpected panics, improve debuggability, and align with best practices.

Key changes:

  • Introduced thiserror and anyhow dependencies.
  • Created AppError enum in src/error.rs covering I/O, Python, security, configuration, and other error cases.
  • Replaced all panicking calls in fix/, misc.rs, main.rs, and shells/ with ?, map_err, and ok_or_else.
  • Updated function signatures to return AppResult<T> (type alias for Result<T, AppError>).
  • In main.rs, changed return type to anyhow::Result<()> and added context messages.
  • Adjusted tests to use .unwrap() for extracting values from Result, keeping them loud on failure.
  • Left a few .expect() calls in places where failure is unrecoverable or guaranteed by logic (e.g., raw mode, command selection bounds, hardcoded regex)

All existing tests pass, and manual testing confirms no regressions.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

  • Added unit tests (updated existing tests to work with new Result returns)
  • Manual testing performed
  • All existing tests pass

Checklist

  • Code follows project style
  • Self-review completed
  • Documentation updated (added comments in code, updated PR description)
  • Tests added/updated

Closes #15

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 60.55046% with 86 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/fix.rs 8.57% 32 Missing ⚠️
src/main.rs 0.00% 26 Missing ⚠️
src/fix/rust.rs 45.71% 19 Missing ⚠️
src/fix/python.rs 90.90% 6 Missing ⚠️
src/shells/generic.rs 0.00% 3 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #22      +/-   ##
==========================================
- Coverage   80.59%   79.59%   -1.01%     
==========================================
  Files          17       17              
  Lines        1716     1774      +58     
==========================================
+ Hits         1383     1412      +29     
- Misses        333      362      +29     
Files with missing lines Coverage Δ
src/fix/rust/cargo_no_command.rs 100.00% <100.00%> (ø)
src/fix/rust/mkdir_p.rs 100.00% <100.00%> (ø)
src/fix/structs.rs 100.00% <100.00%> (ø)
src/misc.rs 99.52% <100.00%> (+0.50%) ⬆️
src/shells/enums.rs 80.00% <100.00%> (+0.68%) ⬆️
src/shells/generic.rs 0.00% <0.00%> (ø)
src/fix/python.rs 90.37% <90.90%> (+0.45%) ⬆️
src/fix/rust.rs 79.12% <45.71%> (-16.72%) ⬇️
src/main.rs 0.00% <0.00%> (ø)
src/fix.rs 29.23% <8.57%> (-1.85%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AsfhtgkDavid
Copy link
Owner

hmm why fmt failed?

@AliyaRazyapova
Copy link
Contributor Author

I managed to fix it, added a commit)

@AsfhtgkDavid AsfhtgkDavid merged commit 1979ca4 into AsfhtgkDavid:main Feb 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor and improve error handling across the project

2 participants