Option type return a custom error?

is it possible for the function Iterator::position to return a custom error when a None is reached? This compiles but i'm not so sure.

#[pallet::weight(T::WeightInfo::propose())]
pub fn donate (
  proposal_hash: T::Hash
) -> DispatchResult {

  let public_props = PublicProps::<T>::get();
  public_props.iter().position(|p| p == proposal_hash).ok_or(Error::<T>::ProposalMissing)?;
}

Trying to add a new public function...
https://github.com/paritytech/substrate/blob/master/frame/democracy/src/lib.rs

What's wrong with the ok_or solution?

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.