Problem
Across all contracts, storage.rs files use .expect("loan not found") and similar patterns when reading persistent storage. These produce opaque VM traps with no error code, making the API unable to distinguish "loan does not exist" from "contract panicked unexpectedly".
Context
Every contract error must be a typed ContractError so the API can translate it to a proper HTTP status code. Right now, any missing storage read returns a 500 to the mobile app instead of a 404, which makes the user-facing error stories incoherent.
Before Starting
Read these context files first:
- context/architecture-context.md
- context/code-standards.md
- context/progress-tracker.md
- contracts/*/src/storage.rs
- contracts/*/src/errors.rs
What To Build
- Audit every
.expect(...) and .unwrap() call across all 5 storage.rs files. Use rg -n "expect\(|unwrap\(\)" contracts/*/src/storage.rs.
- For each, change the function signature to return
Result<T, ContractError>.
- Replace
.expect("loan not found") with .ok_or(ContractError::LoanNotFound)?.
- Update callers in
lib.rs to propagate with ?.
- Add missing error variants where needed (e.g.
PoolNotInitialized, VendorNotFound).
- Add a regression test per contract: call a getter before
initialize() and assert NotInitialized is returned (not a panic).
Files To Touch
contracts/creditline-contract/src/storage.rs, errors.rs, lib.rs, tests.rs
contracts/liquidity-pool-contract/src/storage.rs, errors.rs, lib.rs, tests.rs
contracts/reputation-contract/src/storage.rs, errors.rs, lib.rs, tests.rs
contracts/vendor-registry-contract/src/storage.rs, errors.rs, lib.rs, tests.rs
contracts/token-mock-contract/src/storage.rs, errors.rs, lib.rs, tests.rs
Acceptance Criteria
Mandatory Checks Before PR
Problem
Across all contracts,
storage.rsfiles use.expect("loan not found")and similar patterns when reading persistent storage. These produce opaque VM traps with no error code, making the API unable to distinguish "loan does not exist" from "contract panicked unexpectedly".Context
Every contract error must be a typed
ContractErrorso the API can translate it to a proper HTTP status code. Right now, any missing storage read returns a 500 to the mobile app instead of a 404, which makes the user-facing error stories incoherent.Before Starting
Read these context files first:
What To Build
.expect(...)and.unwrap()call across all 5storage.rsfiles. Userg -n "expect\(|unwrap\(\)" contracts/*/src/storage.rs.Result<T, ContractError>..expect("loan not found")with.ok_or(ContractError::LoanNotFound)?.lib.rsto propagate with?.PoolNotInitialized,VendorNotFound).initialize()and assertNotInitializedis returned (not a panic).Files To Touch
contracts/creditline-contract/src/storage.rs,errors.rs,lib.rs,tests.rscontracts/liquidity-pool-contract/src/storage.rs,errors.rs,lib.rs,tests.rscontracts/reputation-contract/src/storage.rs,errors.rs,lib.rs,tests.rscontracts/vendor-registry-contract/src/storage.rs,errors.rs,lib.rs,tests.rscontracts/token-mock-contract/src/storage.rs,errors.rs,lib.rs,tests.rsAcceptance Criteria
.expect()or.unwrap()calls remain in anystorage.rsResult<T, ContractError>Mandatory Checks Before PR