Skip to main content

workflow_utils/
error.rs

1use thiserror::Error;
2
3/// Errors produced by the `workflow-utils` crate.
4#[derive(Error, Debug)]
5pub enum Error {
6    /// A free-form error carrying a custom message.
7    #[error("{0}")]
8    Custom(String),
9
10    /// An underlying I/O error.
11    #[error(transparent)]
12    Io(#[from] std::io::Error),
13
14    /// An error from the `reqwest` HTTP client.
15    #[error(transparent)]
16    Reqwest(#[from] reqwest::Error),
17
18    /// An invalid HTTP header name was supplied.
19    #[error(transparent)]
20    InvalidHeaderName(#[from] reqwest::header::InvalidHeaderName),
21
22    /// An invalid HTTP header value was supplied.
23    #[error(transparent)]
24    InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),
25
26    /// Failed to parse an integer (e.g. while parsing a version component).
27    #[error(transparent)]
28    ParseInt(#[from] std::num::ParseIntError),
29
30    /// An error from the `workflow-http` crate.
31    #[error(transparent)]
32    Http(#[from] workflow_http::error::Error),
33}
34
35impl From<String> for Error {
36    fn from(s: String) -> Self {
37        Error::Custom(s)
38    }
39}
40
41impl From<&str> for Error {
42    fn from(s: &str) -> Self {
43        Error::Custom(s.to_string())
44    }
45}
46
47impl Error {
48    /// Constructs a [`Error::Custom`] from any displayable value.
49    pub fn custom<T: std::fmt::Display>(msg: T) -> Self {
50        Error::Custom(msg.to_string())
51    }
52}
53
54// impl From<reqwest::Error> for Error {
55//     fn from(err: reqwest::Error) -> Self {
56//         Self::Reqwest(err)
57//     }
58// }