Replace storage-read panics with typed errors in escrow contract#281
Merged
Xuccessor merged 2 commits intoJun 20, 2026
Merged
Conversation
Contributor
|
Hey 👋 Nice work on this refactor — swapping assert! panics for a typed |
11 tasks
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.
Closes #156
Problem
The EscrowContract read persistent storage with
.unwrap()in 8 places. Amissing key (uninitialized contract, race condition, key typo, or corruption)
caused the whole transaction to panic and revert with a generic "host error",
costing users gas with no actionable reason and risking locked funds.
Changes
ContractErrorenum (#[contracterror],#[repr(u32)]) with 12descriptive, documented variants, including the required NotInitialized,
AlreadyInitialized, Unauthorized, InvalidStatus, InvalidWinner, and
InsufficientBalance.
.unwrap()storage reads (and the.expect()on the pendingoperation) with typed read helpers using
.ok_or(ContractError::NotInitialized).Result<…, ContractError>; getters returnResult<T, ContractError>.assert_owner/assert_contributor/assert_arbitrator/assert_status/assert_unlockedhelpers and the timelock helpers fromassert!/panic!toResultreturns, threaded with?.AlreadyInitialized, Unauthorized, InvalidStatus, InvalidWinner,
PendingOperationExists, NoPendingOperation, OperationLocked,
OperationAlreadyUnlocked, InvalidOperation).
Tests
#[should_panic]tests replaced withtry_*calls asserting the exactErrvariant (the token-allowance trap usesis_err()).double-fund, resolve with an invalid winner, and execute with no pending
operation.
Note: cargo was unavailable in my environment, so
cargo testandcargo clippystill need to be run locally/CI to confirm green.