Skip to content

fix: annotate CommonError with #[contracterror] and stable u32 codes#584

Open
dzekojohn4 wants to merge 1 commit into
Gatheraa:mainfrom
dzekojohn4:fix/issue-515-common-error-contracterror
Open

fix: annotate CommonError with #[contracterror] and stable u32 codes#584
dzekojohn4 wants to merge 1 commit into
Gatheraa:mainfrom
dzekojohn4:fix/issue-515-common-error-contracterror

Conversation

@dzekojohn4

Copy link
Copy Markdown
Contributor

Summary

CommonError was declared as a plain Rust enum without the #[contracterror] macro, so downstream contracts could not use its variants in Result<T, CommonError> return types. This change wires the macro in and assigns stable discriminant codes.

Changes

  • contract/common/src/lib.rs:
    • Add contracterror to the soroban_sdk import.
    • Annotate CommonError with #[contracterror] and #[derive(Copy, Clone, Debug, Eq, PartialEq)].
    • Assign stable u32 discriminants: InvalidInput=1, Unauthorized=2, NotFound=3, AlreadyExists=4, InternalError=5, RateLimited=6, Maintenance=7.
    • Update errors::error_codes constants to match the new discriminants (1, 2, 3).

Testing

  • cargo check --workspace passes with the annotated enum.
  • Downstream contracts returning Result<T, CommonError> compile without TryFromVal errors.

Closes #515

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][common] Wire CommonError into #[contracterror]

1 participant