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    #[cfg(feature = "yaml")]
21    #[error("failed to parse manifest file `{path}`: {source}")]
22    Parse {
23        path: std::path::PathBuf,
24        #[source]
25        source: serde_yaml_ng::Error,
26    },
27    #[error("failed to add manifest file `{path}` to resolver: {source}")]
28    Insert {
29        path: std::path::PathBuf,
30        #[source]
31        source: InsertManifestError,
32    },
33}
34
35#[cfg(all(feature = "cli", feature = "std"))]
36impl From<FromDirError> for clientele::SysexitsError {
37    fn from(value: FromDirError) -> Self {
38        use FromDirError::*;
39        use clientele::SysexitsError::*;
40        match value {
41            ManifestDirIo { .. } => EX_IOERR,
42            ManifestIo { .. } => EX_IOERR,
43            #[cfg(feature = "yaml")]
44            Parse { .. } => EX_CONFIG,
45            Insert { source, .. } => source.into(),
46        }
47    }
48}
49
50#[derive(Debug, thiserror::Error)]
51pub enum InsertManifestError {
52    #[error("invalid url: {0}")]
53    Url(#[from] UrlParseError),
54    #[error("invalid content type: {0}")]
55    ContentType(#[from] mime::FromStrError),
56}
57
58#[derive(Clone, Debug, thiserror::Error)]
59pub enum UrlParseError {
60    #[error("URL can't be empty")]
61    EmptyUrl,
62    #[error("invalid URL `{url}`: {source}")]
63    InvalidUrl {
64        url: String,
65        #[source]
66        source: url::ParseError,
67    },
68}
69
70#[cfg(all(feature = "cli", feature = "std"))]
71impl From<InsertManifestError> for clientele::SysexitsError {
72    fn from(_value: InsertManifestError) -> Self {
73        clientele::SysexitsError::EX_USAGE
74    }
75}