fix(contracts): use typed errors in deposit and execute_rebalance ins… - #13
Conversation
|
Hi @Rampop01 Thanks for the contribution. Moving from panic!() to typed errors is definitely an improvement for contract usability and testability. A few things I'd like clarified before approval: Since deposit() and execute_rebalance() now return Result<(), Error>, have all downstream callers and generated client bindings been updated accordingly? Also, I noticed the checks are currently failing. Could you share the cause of the CI failure and whether it's related to this change? |
Thanks for the review! Here are the clarifications regarding the points you raised: 1. Downstream Callers & Client BindingsThe repository's internal 2. Large Diff (13 Files)There are no non-error-handling logical changes. The large diff footprint is because Soroban automatically updates interface definition snapshots (JSON files in 3. Panic PathsGood catch! I double-checked the logic and found one remaining panic ( 4. CI FailureThe CI failure was caused by pre-existing, unrelated TypeScript compilation errors in |
|
@Uchechukwu-Ekezie CI pass now, kindly review and merge |
|
Thanks for your breakdown am a good job done @Rampop01 I will be adding more issue soon please I will be glad if you can still apply |
Closes #6
Description
Replaced the untyped
panic!()calls indeposit()andexecute_rebalance()with structured error handling (Result<(), Error>). This allows on-chain callers and SDK clients to catch and handle errors gracefully.Changes Made
contracts/src/types.rs: AddedInvalidAmount(variant 9) to theErrorenum.contracts/src/lib.rs:deposit()andexecute_rebalance()to returnResult<(), Error>.panic!("Amount must be positive")withreturn Err(Error::InvalidAmount).panic!("Emergency stop active")withreturn Err(Error::EmergencyStop).panic!("Cooldown active")withreturn Err(Error::CooldownActive).panic!("Stale price data")withreturn Err(Error::StaleData).contracts/src/test.rs: Updated all relevant tests to use the client'stry_depositandtry_execute_rebalancemethods. They now assert typed errors (e.g.,assert_eq!(result, Err(Ok(Error::InvalidAmount)))) instead of using#[should_panic].