Skip to content

fix(earnings): replace admin() unwrap with typed NotInitialized error - #1498

Merged
aji70 merged 1 commit into
MyFanss:mainfrom
priscaenoch:feature/1374-earnings-notinitialized-error
Jul 24, 2026
Merged

fix(earnings): replace admin() unwrap with typed NotInitialized error#1498
aji70 merged 1 commit into
MyFanss:mainfrom
priscaenoch:feature/1374-earnings-notinitialized-error

Conversation

@priscaenoch

Copy link
Copy Markdown
Contributor

Summary

closes #1374

Earnings::admin() panicked with a raw unwrap() on empty instance storage when the contract had never been initialized, instead of returning a typed contract error. This surfaces as an opaque host panic rather than a decodable Soroban contract error for callers.

  • Added Error::NotInitialized (code 2) to the earnings contract's #[contracterror] enum, appended after the existing AlreadyInitialized (code 1) per the "do not renumber existing variants" rule documented on the enum.
  • admin() now uses .unwrap_or_else(|| panic_with_error!(&env, Error::NotInitialized)), mirroring the exact pattern already used by subscription::MyfansContract::admin().
  • Added test_admin_returns_not_initialized_before_init, which calls try_admin() on a freshly-registered, uninitialized contract and asserts the typed error is returned.

Testing/validation performed

  • Manual code review against the existing subscription contract's identical admin() error-typing pattern for consistency.
  • Note: this sandbox has no Rust toolchain available, so I could not run cargo test -p earnings, cargo fmt --check, or the wasm build locally. The change is a minimal, mechanical mirror of an existing, already-tested pattern in subscription::admin(), but please confirm CI (cargo test -p earnings) passes before merging.

Issue

#1374

- Add Error::NotInitialized (code 2) to the earnings contract error enum.
- admin() now returns the typed error via panic_with_error! instead of
  panicking on an unwrap() of empty instance storage when the contract
  has never been initialized.
- Add test_admin_returns_not_initialized_before_init covering the
  uninitialized-view path via try_admin().

Closes MyFanss#1374
@drips-wave

drips-wave Bot commented Jul 23, 2026

Copy link
Copy Markdown

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

@aji70
aji70 merged commit fb298d3 into MyFanss:main Jul 24, 2026
1 of 7 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.

Contract: Replace earnings admin() unwrap with typed NotInitialized

2 participants