hardening(subscription_renewal): replace panic!/unwrap/expect with typed Result errors - #2
Open
wendypetersondev wants to merge 1 commit into
Open
Conversation
…ped Result errors Closes Calebux#1053 - Add ContractError #[contracterror] enum (19 variants, discriminants 1-19) - Convert init, set_paused, set_logging_contract, acquire_renewal_lock, release_renewal_lock, cancel_sub, approve_renewal, renew, get_sub, get_lifecycle, set_window, set_user_cap to return Result<T, ContractError> - Replace every panic!/expect()/unwrap() on user-reachable paths with typed Err(ContractError::*) — zero bare panics remain - Rename IntegrityViolation/RenewalLockExpired event structs to IntegrityViolationEvent/RenewalLockExpiredEvent to avoid clash with enum - Update all #[should_panic] tests to use try_* client methods and assert_eq!(err, ContractError::Variant) patterns - Update fuzz tests: remove catch_unwind, assert typed error codes instead - No logic changes; all invariants and spending caps preserved
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
Closes Calebux#1053
Replaces all ~20 bare
panic!/.expect()/.unwrap()calls on user-reachable paths insubscription_renewal/src/lib.rswith a#[contracterror]enum, so clients receive predictable, inspectable error codes instead of opaque contract panics.Changes
lib.rsContractErrorenum with 19 variants (discriminants 1–19, required by Soroban ABI):AlreadyInitialized,NotInitialized,ProtocolPaused,RenewalLockActive,NoRenewalLock,SubscriptionNotFound,AlreadyCancelled,LifecycleNotFound,SubscriptionFailed,RenewalLockRequired,RenewalLockExpired,DuplicateCycle,CooldownActive,InvalidApproval,OutsideRenewalWindow,IntegrityViolation,SpendingCapExceeded,GlobalCapExceeded,InvalidWindowResult<T, ContractError>IntegrityViolationandRenewalLockExpiredevent structs toIntegrityViolationEvent/RenewalLockExpiredEventto avoid name collision with error enum variantspanic!/.expect()/.unwrap()remain on any user-reachable pathtest.rs#[should_panic(expected = "...")]tests withtry_*client method calls andassert_eq!(err, ContractError::Variant)assertions.unwrap()fuzz.rscatch_unwind/AssertUnwindSafe— fuzz harnesses now usetry_*and assert typed error codesAcceptance criteria
ContractErrorenum exposed in contract ABI