Feat/error - #52
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Errorenum in campaign/src/lib.rs now includes all 23 required error variants from the acceptance criteria, plus some legacy variants maintained for backward compatibility:2. Comprehensive Documentation
Every single error variant includes:
3. Eliminated All Unlabelled Panics
All
expect()calls that were panicking with string messages have been replaced with proper typed errors:"campaign not initialized"→ now returnsError::NotInitialized"XLM token address not set"→ now returnsError::NotInitialized"previous milestone not found"→ now returnsError::MilestoneNotFound"MilestoneNotFound"string panic → now returns properError::MilestoneNotFound4. Improved Error Accuracy
Error::Reentrantinstead of genericUnauthorizedError::ContractFrozeninstead of genericUnauthorizedError::AssetNotAccepted(matches the required name)Error::Overflowas requiredCannotCancelWithFundscheck that prevents cancelling a campaign with remaining funds5. 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 returnsResult<CampaignData, Error>require_creator()→ now returnsResult<(), Error>get_milestone()→ already properly returned a Result, now usesget_campaign_data()?get_all_milestones()→ now returnsResult<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:
All acceptance criteria have been met! The error system is now fully typed, documented, and free of unlabelled string panics.
closes #41