Context
Currently, contract functions panic on invalid inputs or edge cases. This creates poor UX and makes debugging difficult for frontend integration. We need structured error types that communicate specific failure reasons to callers.
Problem
- No custom error types defined; functions use unwrap() which panics
- Frontend cannot distinguish between different failure modes (invalid token, insufficient balance, swap validation failure)
- Error messages are unhelpful for debugging or user-facing UI
What "Done" Looks Like
Implementation Guidelines
- Define error enum in a new
errors.rs module
- Use Soroban's Result with custom error mapping
- Ensure error types serialize properly for contract invocation responses
- Reference: Soroban error handling docs
- Watch for: Panic paths in trading.rs and portfolio.rs logic
Acceptance Criteria
Validation
- All tests pass with new error handling
- No panics occur on invalid inputs (test with malformed data)
- Error enum variants are clearly documented
Context
Currently, contract functions panic on invalid inputs or edge cases. This creates poor UX and makes debugging difficult for frontend integration. We need structured error types that communicate specific failure reasons to callers.
Problem
What "Done" Looks Like
ContractErrorenum covering all failure modes:Implementation Guidelines
errors.rsmoduleAcceptance Criteria
ContractErrorenum implemented with 5+ error variantsResult<T, ContractError>(0 unwrap() calls in public API)Validation