Skip to content

[Chore] Replace v1's bare unwrap() calls with expect() #108

Description

@collinsezedike

Summary

contracts/tholos/src/lib.rs has two bare .unwrap() calls on invariant-backed values, at line 784 (assertion.disputer.clone().unwrap()) and lines 874/876 (resolvers.get(i).unwrap() / resolvers.get(j).unwrap()). Both are provably safe given the surrounding invariants (a disputed assertion always has a disputer; the loop bounds never exceed resolvers' length), but v2 consistently uses self-documenting .expect("...") for equivalent invariant-backed unwraps instead of bare .unwrap(). This is a readability/convention fix, not a correctness fix, nothing here is actually reachable as a panic.

Scope

  • Replace the three .unwrap() calls (line 784, 874, 876) with .expect("..."), each message stating the invariant that makes it safe (e.g. why disputer is guaranteed Some at that point, why the index is guaranteed in bounds).
  • No behavior change. No new tests required, this doesn't change what's reachable, only what a panic message says if the invariant were ever violated.

Proposed approach

Read the code immediately preceding each call site to state the actual invariant precisely in the .expect() message (not a generic "should never happen"), matching the style already used throughout contracts/tholos-v2/src/lib.rs's .expect() calls.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaigneasySmall, low-risk changeenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions