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