asimov_module/resolve/
error.rs

1// This is free and unencumbered software released into the public domain.
2
3use alloc::string::String;
4
5#[cfg(feature = "std")]
6#[derive(Debug, thiserror::Error)]
7pub enum FromDirError {
8    #[error("failed to read manifest directory `{path}`: {source}")]
9    ManifestDirIo {
10        path: std::path::PathBuf,
11        #[source]
12        source: std::io::Error,
13    },
14    #[error("failed to read manifest file `{path}`: {source}")]
15    ManifestIo {
16        path: std::path::PathBuf,
17        #[source]
18        source: std::io::Error,
19    },
20    #[error("failed to parse manifest file `{path}`: {source}")]
21    Parse {
22        path: std::path::PathBuf,
23        #[source]
24        source: serde_yml::Error,
25    },
26    #[error("failed to add manifest file `{path}` to resolver: {source}")]
27    Insert {
28        path: std::path::PathBuf,
29        #[source]
30        source: UrlParseError,
31    },
32}
33
34#[cfg(all(feature = "cli", feature = "std"))]
35impl From<FromDirError> for clientele::SysexitsError {
36    fn from(value: FromDirError) -> Self {
37        use FromDirError::*;
38        use clientele::SysexitsError::*;
39        match value {
40            ManifestDirIo { .. } => EX_IOERR,
41            ManifestIo { .. } => EX_IOERR,
42            Parse { .. } => EX_CONFIG,
43            Insert { source, .. } => source.into(),
44        }
45    }
46}
47
48#[derive(Clone, Debug, thiserror::Error)]
49pub enum UrlParseError {
50    #[error("URL can't be empty")]
51    EmptyUrl,
52    #[error("invalid URL `{url}`: {source}")]
53    InvalidUrl {
54        url: String,
55        #[source]
56        source: url::ParseError,
57    },
58}
59
60#[cfg(all(feature = "cli", feature = "std"))]
61impl From<UrlParseError> for clientele::SysexitsError {
62    fn from(_value: UrlParseError) -> Self {
63        clientele::SysexitsError::EX_USAGE
64    }
65}