feat: add unified error handling and custom error types#23
Merged
ayshadogo merged 4 commits intoDfunder:mainfrom Mar 5, 2026
Merged
Conversation
Closes Dfunder#10 - Create `src/errors.rs` with `StellarAidError` enum covering all required variants: HorizonError, SorobanError, KeypairError, ValidationError, TransactionFailed, ContractError, NetworkError - Derive `Display` and `Error` via `thiserror` for ergonomic error handling - Implement `From` conversions for existing error types (KeyError, StellarError, TokenSetupError, reqwest::Error) enabling `?` propagation - Replace bare `unwrap()` calls in production contract code with `expect()` providing descriptive panic messages (campaign and withdrawal contracts) - Replace `unwrap_or_default()` in friendbot with proper `?` error propagation - Add comprehensive unit tests for all error conversions and formatting Made-with: Cursor
Contributor
|
Please resolve Conflicts |
Contributor
Author
|
@ayshadogo done, please check them out |
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
Close #10 — Error Handling and Custom Error Types
src/errors.rswith a unifiedStellarAidErrorenum covering all seven required variants:HorizonError,SorobanError,KeypairError,ValidationError,TransactionFailed,ContractError,NetworkErrorthiserror(already a dependency) to deriveDisplayandErrortraits ergonomicallyFromconversions for existing error types (KeyError,StellarError,TokenSetupError,reqwest::Error) so the?operator works seamlessly across module boundariesunwrap()calls in production code paths:contracts/campaign/src/lib.rs: replaced 2×unwrap()→expect("campaign not initialized")contracts/withdrawal/src/lib.rs: replaced 1×unwrap()→expect("withdrawal not initialized")src/friendbot/utils/friendbot.rs: replacedunwrap_or_default()→ propermap_err+?propagationFromconversions andDisplayformattingFiles Changed
src/errors.rsStellarAidErrorenum withFromimpls and testssrc/main.rspub mod errorscontracts/campaign/src/lib.rsunwrap()→expect()with descriptive messagescontracts/withdrawal/src/lib.rsunwrap()→expect()with descriptive messagesrc/friendbot/utils/friendbot.rsunwrap_or_default()→?error propagationTest plan
cargo check -p contract-fox— compiles without errorscargo test -p contract-fox— all 41 tests pass (34 existing + 7 new)unwrap()remains