Skip to content

Commit

Permalink
Merge pull request #13 from fission-codes/wrap_auto_cid_insert
Browse files Browse the repository at this point in the history
Wrap auto CID Insert error
  • Loading branch information
matheus23 authored Mar 26, 2024
2 parents 13510c5 + bc0a275 commit ff87859
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/delegation/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libipld_core::ipld::Ipld;
use libipld_core::{cid::Cid, codec::Codec};
use nonempty::NonEmpty;
use std::{fmt::Debug, sync::Arc};
use thiserror::Error;
use web_time::SystemTime;

pub trait Store<DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec + TryFrom<u64> + Into<u64>>
Expand All @@ -26,8 +27,12 @@ where
cid: &Cid,
) -> Result<Option<Arc<Delegation<DID, V, C>>>, Self::DelegationStoreError>;

fn insert(&self, delegation: Delegation<DID, V, C>) -> Result<(), Self::DelegationStoreError> {
self.insert_keyed(delegation.cid().expect("FIXME"), delegation)
fn insert(
&self,
delegation: Delegation<DID, V, C>,
) -> Result<(), CannotCidOr<Self::DelegationStoreError>> {
self.insert_keyed(delegation.cid()?, delegation)
.map_err(CannotCidOr::StoreError)
}

fn insert_keyed(
Expand Down Expand Up @@ -128,3 +133,12 @@ where
(**self).get_chain(audience, subject, command, policy, now)
}
}

#[derive(Debug, Error)]
pub enum CannotCidOr<E> {
#[error("Cannot make CID from delegation based on supplied Varsig")]
CannotMakeCid(#[from] libipld_core::error::Error),

#[error("Store error: {0}")]
StoreError(E),
}

0 comments on commit ff87859

Please sign in to comment.