Skip to content

Add comprehensive error types and error handling - #126

Merged
manoahLinks merged 2 commits into
crowdpass-live:mainfrom
Wetshakat:feat/Add-comprehensive-error-types-and-error-handling
Mar 28, 2026
Merged

Add comprehensive error types and error handling#126
manoahLinks merged 2 commits into
crowdpass-live:mainfrom
Wetshakat:feat/Add-comprehensive-error-types-and-error-handling

Conversation

@Wetshakat

Copy link
Copy Markdown

closed #79

Add Comprehensive Error Types and Error Handling

Summary

Replaces all panic!(), .expect(), and untyped .unwrap() calls across every contract with
typed #[contracterror] error enums and Result return types. This gives callers
structured, machine-readable error codes instead of opaque panic strings.

Motivation

String-based panics make it impossible for frontend clients and integrators to
programmatically handle errors. Typed error enums with numeric codes allow:

  • Frontend apps to match on specific error codes and show user-friendly messages
  • Integration tests to assert on exact error variants
  • Cross-contract callers to handle failures gracefully instead of catching panics

Changes by Contract

event_manager

5 new error variants added:

Code Name Replaces
11 EventNotCanceled panic!("Event is not canceled")
12 RefundAlreadyClaimed panic!("Refund already claimed")
13 NotABuyer panic!("Claimer did not purchase a ticket")
14 EventSoldOut panic!("Event is sold out")
15 TicketsBelowSold panic!("Cannot reduce total_tickets below tickets_sold")

Functions converted to Result:

  • claim_refund — was (), now Result<(), Error>
  • update_event — was (), now Result<(), Error>
  • purchase_ticket — was (), now Result<(), Error>

Also removed a dangling duplicate panic!("Ticket factory not initialized") line in
deploy_ticket_nft helper.

ticket_nft

1 new error variant:

Code Name Replaces
5 NotInitialized .unwrap() / .expect("Not initialized")

Functions converted to Result:

  • burn — was (), now Result<(), Error>
  • get_minter — was Address, now Result<Address, Error>
  • mint_ticket_nft — internal .unwrap() replaced with ?

tba_registry

1 new error variant:

Code Name Replaces
2 NotInitialized .expect("Registry not initialized")

Changed in create_account: .expect() → .ok_or(Error::NotInitialized)?

ticket_factory

Entirely new Error enum (contract had none):

Code Name Description
1 NotInitialized Storage not set (pre-constructor)
2 Unauthorized Caller is not admin

Functions converted to Result:

  • deploy_ticket — was Address, now Result<Address, Error>
  • get_admin — was Address, now Result<Address, Error>

tba_account

No changes needed — already used typed errors throughout.

Test Updates

  • event_manager/src/lib.rs (update_event_tests): 5 #[should_panic] tests → try_
    assertions
  • event_manager/src/test.rs: 5 #[should_panic] tests → try_ assertions
  • ticket_factory/src/test.rs: Added .unwrap() to 8 deploy_ticket, 1 get_admin, 1
    get_minter calls

Files Changed

File Changes
soroban-contract/contracts/event_manager/src/lib.rs 5 new errors, 3 functions →
Result, 17 panics removed
soroban-contract/contracts/event_manager/src/test.rs 5 tests converted from should_
panic to try_
soroban-contract/contracts/ticket_nft/src/lib.rs 1 new error, 2 functions → Result,
1 unwrap removed
soroban-contract/contracts/tba_registry/src/lib.rs 1 new error, 1 expect removed
soroban-contract/contracts/ticket_factory/src/lib.rs New Error enum, 2 functions →
Result, 3 unwraps removed
soroban-contract/contracts/ticket_factory/src/test.rs 10 calls updated with .unwrap(
)

How to Verify

  1. Check that zero panic!(), .expect(), or untyped .unwrap() calls remain in any
    contract's non-test code
  2. All #[should_panic] tests have been converted (except 2 legitimate auth-failure tests
    in ticket_nft and tba_account)
  3. Error codes are sequential and unique within each contract

event_manager:
- Add error variants: EventNotCanceled(11), RefundAlreadyClaimed(12),
  NotABuyer(13), EventSoldOut(14), TicketsBelowSold(15)
- Convert claim_refund, update_event, purchase_ticket to return Result
- Update tests from #[should_panic] to try_ assertions

ticket_nft:
- Add NotInitialized(5) error variant
- Convert burn, get_minter to return Result
- Replace .unwrap() in mint_ticket_nft with typed error

tba_registry:
- Add NotInitialized(2) error variant
- Replace .expect() in create_account with typed error

ticket_factory:
- Add new Error enum with NotInitialized(1), Unauthorized(2)
- Convert deploy_ticket, get_admin to return Result

tba_account:
- Already uses typed errors throughout (no changes needed)
@drips-wave

drips-wave Bot commented Mar 27, 2026

Copy link
Copy Markdown

@Wetshakat Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@manoahLinks
manoahLinks merged commit a3ace9b into crowdpass-live:main Mar 28, 2026
0 of 2 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.

Add comprehensive error types and error handling

2 participants