Skip to content

Commit

Permalink
feat(cognitarium): add rdf parsing related errors
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Jun 1, 2023
1 parent 9667847 commit 7c25908
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions contracts/okp4-cognitarium/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use cosmwasm_std::{StdError, Uint128};
use rio_turtle::TurtleError;
use rio_xml::RdfXmlError;
use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("{0}")]
ParseRDF(#[from] RDFParseError),

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

Expand All @@ -16,6 +21,18 @@ pub enum ContractError {
NotImplemented,
}

impl From<RdfXmlError> for ContractError {
fn from(value: RdfXmlError) -> Self {
ContractError::ParseRDF(RDFParseError::from(value))
}
}

impl From<TurtleError> for ContractError {
fn from(value: TurtleError) -> Self {
ContractError::ParseRDF(RDFParseError::from(value))
}
}

#[derive(Error, Debug, PartialEq)]
pub enum StoreError {
#[error("Maximum triples number exceeded: {0}")]
Expand All @@ -39,3 +56,23 @@ pub enum StoreError {
#[error("Maximum insert triple count exceeded: {0}")]
MaxInsertDataTripleCount(Uint128),
}

#[derive(Error, Debug, PartialEq)]
pub enum RDFParseError {
#[error("Error parsing XML RDF: {0}")]
XML(String),
#[error("Error parsing Turtle RDF: {0}")]
Turtle(String),
}

impl From<RdfXmlError> for RDFParseError {
fn from(value: RdfXmlError) -> Self {
RDFParseError::XML(value.to_string())
}
}

impl From<TurtleError> for RDFParseError {
fn from(value: TurtleError) -> Self {
RDFParseError::XML(value.to_string())
}
}
2 changes: 1 addition & 1 deletion contracts/okp4-cognitarium/src/state/triples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<'a> TryFrom<rio_api::model::Term<'a>> for Object {
rio_api::model::Term::Literal(literal) => {
Literal::try_from(literal).map(|l| Object::Literal(l))
}
_ => Err(StdError::generic_err("Not implemented")),
_ => Err(StdError::generic_err("RDF star syntax unsupported")),
}
}
}
Expand Down

0 comments on commit 7c25908

Please sign in to comment.