1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
use super::parser::Rule;
/// The result type for this crate.
pub type Result<T> = std::result::Result<T, Error>;
/// The error type for this crate.
#[derive(Debug, Error)]
pub enum Error {
/// An error that occurred at the `pest` parser level.
///
/// This is returned from any parsing methods when the input is written
/// with invalid syntax, or when attempting to parse an incomplete input.
///
/// # Example:
/// ```rust
/// # #[macro_use] extern crate matches;
/// # extern crate horned_owl;
/// # use horned_owl::ontology::set::SetOntology;
/// use horned_functional::FromFunctional;
///
/// let res = SetOntology::from_ofn("Ontology(");
/// assert_matches!(res, Err(horned_functional::Error::Pest(_)));
/// ```
#[error(transparent)]
Pest(#[from] pest::error::Error<Rule>),
/// An error that happened at the I/O level.
///
/// # Example:
/// ```rust
/// # #[macro_use] extern crate matches;
/// # use horned_owl::ontology::set::SetOntology;
/// let res = horned_functional::from_file::<SetOntology, _>("/some/missing/file")
/// .map(|x| x.0);
/// assert_matches!(res, Err(horned_functional::Error::IO(_)));
/// ```
#[error(transparent)]
IO(#[from] std::io::Error),
/// A CURIE expansion went wrong.
///
/// This error can be encountered in documents where a CURIE used an
/// undefined prefix, or when attempting to parse an abbreviated IRI
/// without providing a prefix mapping.
///
/// # Example
/// ```rust
/// # #[macro_use] extern crate matches;
/// # extern crate horned_owl;
/// # use horned_owl::model::IRI;
/// use horned_functional::FromFunctional;
///
/// let res = IRI::from_ofn("example:Entity");
/// assert_matches!(res, Err(horned_functional::Error::Expansion(_)));
/// ```
#[error("expansion error: {0:?}")]
Expansion(curie::ExpansionError),
/// An unknown IRI was used as a facet.
///
/// # Example
/// ```rust
/// # #[macro_use] extern crate matches;
/// # use horned_owl::model::Facet;
/// use horned_functional::FromFunctional;
///
/// let res = Facet::from_ofn("<http://example.com/thing>");
/// assert_matches!(res, Err(horned_functional::Error::InvalidFacet(_)));
/// ```
#[error("invalid facet: {0}")]
InvalidFacet(String),
/// An unsupported construct was used.
///
/// See the relevant issue for each unsupported syntax construct; if the
/// issue has been resolved, please open an issue on the
/// [`fastobo/horned-functional`](https://github.com/fastobo/horned-functional)
/// repository so that it can be fixed.
#[error("unsupported: {0} (see {1})")]
Unsupported(&'static str, &'static str),
}
impl From<curie::ExpansionError> for Error {
fn from(e: curie::ExpansionError) -> Self {
Error::Expansion(e)
}
}