Skip to content

Commit

Permalink
avoid expect/expect_err (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk authored Mar 13, 2024
1 parent 3779acc commit bde5ab3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pallets/pooled-staking/src/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ impl<T: Config> Candidates<T> {
stake: new_stake.0,
};

let pos = list
.binary_search(&entry)
.expect_err("Candidate should be present at most once in the list.");
// Candidate should not appear in the list, we're instead searching where
// to insert it.
let Err(pos) = list.binary_search(&entry) else {
return Err(Error::<T>::InconsistentState);
};

if pos >= T::EligibleCandidatesBufferSize::get() as usize {
None
Expand All @@ -176,7 +178,8 @@ impl<T: Config> Candidates<T> {
list.insert(pos, entry.clone());
list.truncate(T::EligibleCandidatesBufferSize::get() as usize)
})
.expect("list is truncated using the vec bound");
// This should not occur as we truncate the list above.
.ok_or(Error::<T>::InconsistentState)?;

Some(pos as u32)
}
Expand Down

0 comments on commit bde5ab3

Please sign in to comment.