📋 Description
create_policy and pay_premium in insurance/src/lib.rs use panic! for several validation conditions (name, premium, coverage, combination) even though the crate defines a full InsuranceError enum (InvalidName, InvalidPremium, InvalidCoverageAmount, UnsupportedCombination, PolicyInactive, etc.). These panics abort with opaque host errors instead of the typed codes the rest of the contract uses.
This issue converts the reachable validation panics in create_policy and pay_premium to typed InsuranceError returns.
Why this matters: Insurance feeds Reporting's get_insurance_report and orchestrated premium flows. A panic on invalid input aborts the whole call chain instead of returning a code a caller can branch on, and panics are far harder to test and audit than typed errors.
🎯 Requirements & Context
Functional requirements
Context & constraints
🛠️ Suggested Execution
1. Fork & branch
git checkout -b refactor/insurance-typed-errors
2. Implement changes
- Convert the panic sites and change signatures to
Result<_, InsuranceError> where needed in insurance/src/lib.rs.
- Add
/// doc comments listing each entrypoint's error codes.
3. Test & commit
- Cover edge cases: each
TypeConstraints min/max boundary, unsupported coverage/amount combination, pay on inactive policy, pay on missing policy.
Example commit message
refactor(insurance): return typed InsuranceError from create_policy and pay_premium
Replaces validation panics with InvalidName/InvalidPremium/UnsupportedCombination etc.
✅ Acceptance Criteria & Guidelines
| Requirement |
Target |
| Validation panics replaced with typed errors |
Required |
TypeConstraints bounds honored |
Required |
| Coverage of validation paths |
≥ 95%, all branches |
| Doc comments listing error codes |
Required |
cargo test -p insurance + cargo clippy clean |
Required |
| Timeframe |
96 hours from assignment |
💬 Community & Support
Join the Remitwise contributor community on Discord: https://discord.gg/CtQuPZFMA — comment when you pick this up. 🚀
📋 Description
create_policyandpay_premiumininsurance/src/lib.rsusepanic!for several validation conditions (name, premium, coverage, combination) even though the crate defines a fullInsuranceErrorenum (InvalidName,InvalidPremium,InvalidCoverageAmount,UnsupportedCombination,PolicyInactive, etc.). These panics abort with opaque host errors instead of the typed codes the rest of the contract uses.This issue converts the reachable validation panics in
create_policyandpay_premiumto typedInsuranceErrorreturns.🎯 Requirements & Context
Functional requirements
create_policywithInvalidName/InvalidPremium/InvalidCoverageAmount/UnsupportedCombination.pay_premiumvalidation panics (inactive policy, missing policy) withPolicyInactive/PolicyNotFound.CoverageTypebounds inTypeConstraints::for_typewhen validating.Context & constraints
21.7.7; reuse existingInsuranceErrorvariants.next_payment_dateadvancement unchanged.cargo test -p insurance.🛠️ Suggested Execution
1. Fork & branch
2. Implement changes
Result<_, InsuranceError>where needed ininsurance/src/lib.rs.///doc comments listing each entrypoint's error codes.3. Test & commit
cargo test -p insuranceTypeConstraintsmin/max boundary, unsupported coverage/amount combination, pay on inactive policy, pay on missing policy.Example commit message
✅ Acceptance Criteria & Guidelines
TypeConstraintsbounds honoredcargo test -p insurance+cargo clippyclean💬 Community & Support
Join the Remitwise contributor community on Discord: https://discord.gg/CtQuPZFMA — comment when you pick this up. 🚀