xsd_parser/parser/
error.rs

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
use std::io::Error as IoError;

use thiserror::Error;
use url::{ParseError as UrlParseError, Url};

use crate::quick_xml::Error as XmlError;

/// Represents the errors that are raised by the [`Parser`](super::Parser).
#[derive(Debug, Error)]
pub enum Error<E> {
    /// An IO error occurred.
    #[error("IO Error: {0}")]
    IoError(#[from] IoError),

    /// Error while interpreting the XML for the schema.
    #[error("XML Error: {0}")]
    XmlError(#[from] XmlError),

    /// Error while paring the URL.
    #[error("URL Parse Error: {0}")]
    UrlParseError(#[from] UrlParseError),

    /// Unable to resolve the requested resource.
    #[error("Unable to resolve requested resource: {0}")]
    UnableToResolve(Url),

    /// Error while resolving the requested resource.
    #[error("Resolver Error: {0}")]
    Resolver(E),

    /// Schema is missing a target namespace!
    #[error("Schema is missing a target namespace!")]
    MissingTargetNamespace,

    /// Schema is missing a namespace prefix for the target namespace!
    #[error("Schema is missing a namespace prefix for the target namespace!")]
    MissingTargetNamespacePrefix,
}

impl<E> Error<E> {
    /// Create a [`Error::Resolver`] from the passed `error`.
    pub fn resolver<X: Into<E>>(error: X) -> Self {
        Self::Resolver(error.into())
    }
}