Skip to content

feat: introduce standardized contract error codes and replace string …#528

Open
oyinade247 wants to merge 1 commit into
GalactiGuild:mainfrom
oyinade247:Custom-Error-Code-Registry
Open

feat: introduce standardized contract error codes and replace string …#528
oyinade247 wants to merge 1 commit into
GalactiGuild:mainfrom
oyinade247:Custom-Error-Code-Registry

Conversation

@oyinade247
Copy link
Copy Markdown

closes #348

Pull Request: Centralize Contract Panics into Definitive Error Enum

Summary This PR implements a centralized error handling system for the Soroban contracts. By replacing generic panic!() calls with a #[contracterror] enum, we enable frontend SDKs to receive specific u32 error codes. This allows for precise error reporting and user-friendly tooltips (e.g., "Bounty Not Found" instead of a generic "Panic").

Core Changes

  • New Error Module: Created contract/src/errors.rs with the ErrorCode enum.
  • Refactored Panics: Updated the following modules to use panic_with_error!:
    • lib.rs: Initialization checks.
    • bounty/mod.rs: Authorization, claim checks, and bounty lookups.
    • treasury/management.rs: Balance checks, budget enforcement, and treasury lookups.
  • Documentation: Created contract/ERRORS.md to map u32 codes to descriptions and recommended UI tooltips for frontend developers.
  • Reference Module: Added contract/src/dummy.rs to demonstrate the standard implementation pattern.

Mapped Error Codes

Code | Enum Value | Description -- | -- | -- 1 | Unauthorized | Permission denied for the caller. 2 | InsufficientFunds | Balance is too low for the transaction. 3 | BountyNotFound | Specified bounty ID does not exist. 4 | AlreadyInitialized | Contract setup has already been completed. 5 | TreasuryNotFound | Specified treasury ID does not exist. 6 | TransactionNotFound | Specified transaction ID does not exist. 7 | BudgetExceeded | Category-specific budget limit reached. 8 | AllowanceExceeded | Admin-specific allowance limit reached.

Testing Refactored logic maintains existing functional behavior while upgrading the revert mechanism to use native Soroban error codes. Verified that panic_with_error! is correctly implemented across the target modules.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 29, 2026

@oyinade247 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

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.

[Contract] Custom Error Code Registry

1 participant