error handling in factory contracts #38
Merged
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.
Pull Request: Improve Error Handling in
StrapexFactory
Contractfeat:error handling in factory contracts
Context
The
StrapexFactory
contract previously lacked structured error handling, making it difficult to debug and ensure proper execution flow. The suggested approach was to use anErrors
module with anenum
and#[error_code]
attributes. However, this approach does not work due to limitations in the current Cairo version. Instead, we opted for a simpler, more effective solution usingconst
error codes.This PR enhances the error-handling mechanism while maintaining compatibility with the existing Cairo contract structure.
Related issue #33
Changes
Implemented
Errors
Module with Constants#[error_code] enum
withconst
values.Updated Constructor to Include Additional Validations
owner
,childHash
, anddepositToken
.Improved
create_strapex_contract
Handlingdeploy_syscall
success.Enhanced
getUserStrapexAccount
andget_childClassHash
Reasons for Not Using Suggested Approach
#[error_code]
and Enum-Based Error Handling Are Not Supported:#[error_code]
annotations.enum
for errors introduces unnecessary complexity whenconst
values suffice.Constants Provide a More Readable and Efficient Approach:
const
values make it easy to reference errors across functions.Acceptance Criteria
General Improvements:
constructor
Function:create_strapex_contract
Function:deploy_syscall
succeeds before proceeding.getUserStrapexAccount
andget_childClassHash
Functions:Type of Change
Testing
Test Instructions
pnpm install
Screenshots
Checklist
Additional Notes
scarb build
: Verified successful compilation with new error handling.