plugx_config/
error.rs

1//! All possible error types.
2
3use url::Url;
4
5/// Main error wrapper.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// Errors from [crate::loader::Error].
9    #[error(transparent)]
10    Load {
11        #[from]
12        source: crate::loader::Error,
13    },
14    /// Errors from [crate::parser::Error].
15    #[error("Error in parsing `{plugin_name}` configuration from `{url}` for `{item}`")]
16    Parse {
17        plugin_name: String,
18        url: Url,
19        item: Box<String>,
20        source: crate::parser::Error,
21    },
22    /// Errors from [plugx_input::schema::InputSchemaError]
23    #[error(transparent)]
24    Validate {
25        #[from]
26        source: plugx_input::schema::InputSchemaError,
27    },
28    #[error(transparent)]
29    Other(#[from] anyhow::Error),
30}
31
32impl From<url::ParseError> for Error {
33    fn from(url_parser_error: url::ParseError) -> Self {
34        Self::Other(anyhow::anyhow!(url_parser_error))
35    }
36}
37
38impl From<(String, Url, String, crate::parser::Error)> for Error {
39    fn from(
40        (plugin_name, url, item, parser_error): (String, Url, String, crate::parser::Error),
41    ) -> Self {
42        Self::Parse {
43            plugin_name,
44            url,
45            item: Box::new(item),
46            source: parser_error,
47        }
48    }
49}