1use hyper::{self, StatusCode};
4use serde_json::Error as SerdeError;
5use thiserror::Error as ThisError;
6
7use futures_util::io::Error as IoError;
8
9pub type Result<T> = std::result::Result<T, Error>;
11
12#[derive(Debug, ThisError)]
13pub enum Error {
14 #[error(transparent)]
15 SerdeJsonError(#[from] SerdeError),
16 #[error(transparent)]
17 Hyper(#[from] hyper::Error),
18 #[error(transparent)]
19 Http(#[from] hyper::http::Error),
20 #[error(transparent)]
21 #[allow(clippy::upper_case_acronyms)]
22 IO(#[from] IoError),
23 #[error("The response is invalid - {0}")]
24 InvalidResponse(String),
25 #[error("error {code} - {message}")]
26 Fault { code: StatusCode, message: String },
27 #[error("The HTTP connection was not upgraded by the docker host")]
28 ConnectionNotUpgraded,
29 #[error("Provided scheme `{0}` is not supported")]
30 UnsupportedScheme(String),
31 #[error("Provided URI is missing authority part after scheme")]
32 MissingAuthority,
33 #[error("Failed to parse url - {0}")]
34 InvalidUrl(url::ParseError),
35 #[error("Failed to parse uri - {0}")]
36 InvalidUri(http::uri::InvalidUri),
37 #[error("Invalid port - {0}")]
38 InvalidPort(String),
39 #[error("Invalid protocol - {0}")]
40 InvalidProtocol(String),
41 #[error(transparent)]
42 MalformedVersion(#[from] containers_api::version::Error),
43 #[error(transparent)]
44 Error(#[from] containers_api::conn::Error),
45 #[error(transparent)]
46 Any(Box<dyn std::error::Error + 'static + Send + Sync>),
47 #[error("{0}")]
48 StringError(String),
49}
50
51impl Clone for Error {
52 fn clone(&self) -> Self {
53 match self {
54 Error::SerdeJsonError(err) => Error::StringError(err.to_string()),
55 Error::IO(err) => Error::StringError(err.to_string()),
56 Error::Error(err) => Error::StringError(err.to_string()),
57 e => e.clone(),
58 }
59 }
60}