📋 Description
Every other contract in the workspace returns a typed #[contracterror] (e.g. RemittanceSplitError, SavingsGoalError, BillPaymentsError), but insurance defines InsuranceError in insurance/src/lib.rs and then does not use it — create_policy, pay_premium, and deactivate_policy all panic! with string messages such as "monthly_premium out of range for coverage type" and "policy not found".
Why this matters: Panics abort the transaction with an opaque host error, so callers (CLI, indexer, and especially the orchestrator cross-contract flow) cannot distinguish a recoverable validation failure from a real fault. Typed errors are the contract's public ABI for failure — the insurance contract is the only one missing it.
🎯 Requirements & Context
Functional requirements
Context & constraints
- Soroban SDK 21.7.7,
#![no_std]. InsuranceClient::try_* methods become the test surface for error assertions.
- Preserve numeric error discriminants already assigned (1..11) to keep ABI stability.
- Do not change validation thresholds — this is a representation change only.
🛠️ Suggested Execution
1. Fork & branch
git checkout -b refactor/insurance-typed-errors
2. Implement changes
- Convert internal helpers
require_initialized, load_policy, validate_ext_ref to return Result.
- Add Rust doc comments documenting which error each public fn can return.
- Update
next_payment_scheduling_tests.rs references if affected.
3. Test & commit
cargo test -p insurance -- --nocapture
cargo clippy -p insurance --all-targets -- -D warnings
- Edge cases: ensure no remaining
panic!/unwrap()/expect() in non-test code paths.
Example commit message
refactor(insurance): return typed InsuranceError instead of panicking
Wires the existing InsuranceError variants into create_policy,
pay_premium and deactivate_policy, aligning insurance with the
workspace error-handling convention.
✅ Acceptance Criteria & Guidelines
| Requirement |
Target |
No panic!/unwrap/expect in non-test insurance code |
Required |
Every variant of InsuranceError reachable & tested |
Required |
| Error coverage of converted paths |
≥ 95% |
cargo test -p insurance + clippy clean |
Required |
| ABI discriminants unchanged |
Required |
| Timeframe |
96 hours from assignment |
💬 Community & Support
Questions and design discussion — join the Remitwise contributor community on Discord: https://discord.gg/CtQuPZFMA
Please comment on the issue when you pick it up so we avoid duplicate work and can unblock you quickly. 🚀
📋 Description
Every other contract in the workspace returns a typed
#[contracterror](e.g.RemittanceSplitError,SavingsGoalError,BillPaymentsError), butinsurancedefinesInsuranceErrorininsurance/src/lib.rsand then does not use it —create_policy,pay_premium, anddeactivate_policyallpanic!with string messages such as"monthly_premium out of range for coverage type"and"policy not found".🎯 Requirements & Context
Functional requirements
create_policy,pay_premium,batch_pay_premiums,set_external_ref,deactivate_policy,get_active_policies, andget_total_monthly_premiumsignatures to returnResult<_, InsuranceError>where they currentlypanic!.InvalidName; bad premium →InvalidPremium; bad coverage →InvalidCoverageAmount; ratio guard →UnsupportedCombination; bad external ref →InvalidExternalRef; cap hit →MaxPoliciesReached; missing policy →PolicyNotFound; inactive →PolicyInactive; non-owner →Unauthorized; uninitialized →NotInitialized.initpanic!("already initialized")withAlreadyInitialized.insurance/src/test.rsto assertResult::Err(InsuranceError::...)instead of#[should_panic].Context & constraints
#![no_std].InsuranceClient::try_*methods become the test surface for error assertions.🛠️ Suggested Execution
1. Fork & branch
2. Implement changes
require_initialized,load_policy,validate_ext_refto returnResult.next_payment_scheduling_tests.rsreferences if affected.3. Test & commit
cargo test -p insurance -- --nocapture cargo clippy -p insurance --all-targets -- -D warningspanic!/unwrap()/expect()in non-test code paths.Example commit message
✅ Acceptance Criteria & Guidelines
panic!/unwrap/expectin non-test insurance codeInsuranceErrorreachable & testedcargo test -p insurance+ clippy clean💬 Community & Support
Questions and design discussion — join the Remitwise contributor community on Discord: https://discord.gg/CtQuPZFMA
Please comment on the issue when you pick it up so we avoid duplicate work and can unblock you quickly. 🚀