cob: Return error on wrong history type

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-12-01 20:06:57 +01:00
parent 81a1ee5cc2
commit 4e0efa4690
No known key found for this signature in database
1 changed files with 4 additions and 1 deletions

View File

@ -44,6 +44,8 @@ pub enum Error {
Identity(#[from] project::IdentityError), Identity(#[from] project::IdentityError),
#[error(transparent)] #[error(transparent)]
Serialize(#[from] serde_json::Error), Serialize(#[from] serde_json::Error),
#[error("unexpected history type '{0}'")]
HistoryType(String),
#[error("object `{1}` of type `{0}` was not found")] #[error("object `{1}` of type `{0}` was not found")]
NotFound(TypeName, ObjectId), NotFound(TypeName, ObjectId),
} }
@ -147,9 +149,10 @@ where
if let Some(cob) = cob { if let Some(cob) = cob {
if cob.manifest().history_type != HISTORY_TYPE { if cob.manifest().history_type != HISTORY_TYPE {
panic!(); return Err(Error::HistoryType(cob.manifest().history_type.clone()));
} }
let (obj, clock) = T::from_history(cob.history())?; let (obj, clock) = T::from_history(cob.history())?;
Ok(Some((obj, clock))) Ok(Some((obj, clock)))
} else { } else {
Ok(None) Ok(None)