xsd_parser/pipeline/parser/
error.rs

1use std::io::Error as IoError;
2use std::path::PathBuf;
3
4use thiserror::Error;
5use url::ParseError as UrlParseError;
6
7use crate::quick_xml::Error as XmlError;
8
9use super::resolver::ResolveRequest;
10
11/// Represents the errors that are raised by the [`Parser`](super::Parser).
12#[derive(Debug, Error)]
13pub enum Error<E> {
14    /// An IO error occurred.
15    #[error("IO Error: {0}")]
16    IoError(#[from] IoError),
17
18    /// Error while interpreting the XML for the schema.
19    #[error("XML Error: {0}")]
20    XmlError(#[from] XmlError),
21
22    /// Error while paring the URL.
23    #[error("URL Parse Error: {0}")]
24    UrlParseError(#[from] UrlParseError),
25
26    /// Unable to resolve the requested resource.
27    #[error("Unable to resolve requested resource: {0}")]
28    UnableToResolve(Box<ResolveRequest>),
29
30    /// Error while resolving the requested resource.
31    #[error("Resolver Error: {0}")]
32    Resolver(E),
33
34    /// Invalid file path!
35    ///
36    /// Is raised if the file path could not be converted to an [`Url`](url::Url).
37    #[error("Invalid file path: {0}!")]
38    InvalidFilePath(PathBuf),
39}
40
41impl<E> Error<E> {
42    /// Create a [`Error::Resolver`] from the passed `error`.
43    pub fn resolver<X: Into<E>>(error: X) -> Self {
44        Self::Resolver(error.into())
45    }
46}