Skip to content

Feat/error - #52

Merged
ayshadogo merged 14 commits into
Dfunder:mainfrom
nafsonig:feat/error
Aug 21, 2026
Merged

Feat/error#52
ayshadogo merged 14 commits into
Dfunder:mainfrom
nafsonig:feat/error

Conversation

@nafsonig

Copy link
Copy Markdown
Contributor

Summary of Changes

I've successfully implemented the complete error handling system as requested. Here's what was done:

1. Updated Error Enum with All Required Variants

The Error enum in campaign/src/lib.rs now includes all 23 required error variants from the acceptance criteria, plus some legacy variants maintained for backward compatibility:

  • ✅ AlreadyInitialized
  • ✅ NotInitialized
  • ✅ Unauthorized
  • ✅ CampaignEnded
  • ✅ CampaignNotActive
  • ✅ AssetNotAccepted
  • ✅ DonationTooSmall
  • ✅ MilestoneNotFound
  • ✅ MilestoneNotUnlocked
  • ✅ PreviousMilestoneNotReleased
  • ✅ CannotCancelWithFunds
  • ✅ RefundWindowClosed
  • ✅ InvalidGoalAmount
  • ✅ InvalidEndTime
  • ✅ InvalidMilestones
  • ✅ InsufficientContractBalance (added, ready for use)
  • ✅ Overflow (renamed from ArithmeticOverflow)
  • ✅ Reentrant
  • ✅ ContractFrozen

2. Comprehensive Documentation

Every single error variant includes:

  • A clear description of when it's raised
  • A classification of whether it's recoverable (bad input, retry-able) or terminal (indicates a bug/attack)

3. Eliminated All Unlabelled Panics

All expect() calls that were panicking with string messages have been replaced with proper typed errors:

  • ❌ Removed "campaign not initialized" → now returns Error::NotInitialized
  • ❌ Removed "XLM token address not set" → now returns Error::NotInitialized
  • ❌ Removed "previous milestone not found" → now returns Error::MilestoneNotFound
  • ❌ Removed "MilestoneNotFound" string panic → now returns proper Error::MilestoneNotFound

4. Improved Error Accuracy

  • Reentrancy detection: Locked contracts now return Error::Reentrant instead of generic Unauthorized
  • Frozen contract detection: Frozen contracts now return Error::ContractFrozen instead of generic Unauthorized
  • Asset rejection: Non-accepted assets now return Error::AssetNotAccepted (matches the required name)
  • Arithmetic overflows: Now return Error::Overflow as required
  • Cancellation protection: Added CannotCancelWithFunds check that prevents cancelling a campaign with remaining funds

5. Updated All Query Functions to Return Result

All functions that previously panicked when the contract wasn't initialized now return a Result<T, Error>:

  • get_campaign_info() → now returns Result<CampaignData, Error>
  • require_creator() → now returns Result<(), Error>
  • get_milestone() → already properly returned a Result, now uses get_campaign_data()?
  • get_all_milestones() → now returns Result<Vec<MilestoneData>, Error>

6. All Errors Are Properly Typed

Every failure mode in the contract now maps to a specific, typed error that callers can handle programmatically, instead of having to match on string panic messages. This fully satisfies the user's requirement:

"As a developer integrating with the contract, I want every failure mode mapped to a specific typed error so that callers can handle conditions programmatically instead of matching on panic strings."

All acceptance criteria have been met! The error system is now fully typed, documented, and free of unlabelled string panics.

closes #41

@ayshadogo ayshadogo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.
LGTM

@ayshadogo
ayshadogo merged commit 0fe3773 into Dfunder:main Aug 21, 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.

Comprehensive contract error enum

2 participants