1use parsec_interface::requests::ResponseStatus;
5use std::error;
6use std::fmt;
7
8#[derive(Debug)]
10pub enum Error {
11 Service(ResponseStatus),
13 Client(ClientErrorKind),
15}
16
17impl fmt::Display for Error {
18 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19 match self {
20 Error::Service(response_status) => response_status.fmt(f),
21 Error::Client(client_error_kind) => client_error_kind.fmt(f),
22 }
23 }
24}
25impl error::Error for Error {}
26
27#[derive(Debug)]
29pub enum ClientErrorKind {
30 Interface(ResponseStatus),
32 Ipc(::std::io::Error),
34 InvalidServiceResponseType,
36 InvalidProvider,
38 NoProvider,
40 NoAuthenticator,
43 MissingParam,
45 NotFound,
47 InvalidSocketAddress,
49 InvalidSocketUrl,
51 #[cfg(feature = "spiffe-auth")]
53 Spiffe(spiffe::workload_api::client::ClientError),
54}
55
56impl From<ClientErrorKind> for Error {
57 fn from(client_error: ClientErrorKind) -> Self {
58 Error::Client(client_error)
59 }
60}
61
62impl From<url::ParseError> for Error {
63 fn from(_: url::ParseError) -> Self {
64 Error::Client(ClientErrorKind::InvalidSocketUrl)
65 }
66}
67
68impl fmt::Display for ClientErrorKind {
69 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
70 match self {
71 ClientErrorKind::Interface(response_status) => response_status.fmt(f),
72 ClientErrorKind::Ipc(error) => error.fmt(f),
73 ClientErrorKind::InvalidServiceResponseType => write!(
74 f,
75 "the opcode of the response does not match the opcode of the request"
76 ),
77 ClientErrorKind::InvalidProvider => {
78 write!(f, "operation not supported by selected provider")
79 }
80 ClientErrorKind::NoProvider => write!(f, "client is missing an implicit provider"),
81 ClientErrorKind::NoAuthenticator => write!(f, "service is not reporting any authenticators or none of the reported ones are supported by the client"),
82 ClientErrorKind::MissingParam => write!(f, "one of the `Option` parameters was required but was not provided"),
83 ClientErrorKind::NotFound => write!(f, "one of the resources required in the operation was not found"),
84 ClientErrorKind::InvalidSocketAddress => write!(f, "the socket address provided in the URL is not valid"),
85 ClientErrorKind::InvalidSocketUrl => write!(f, "the socket URL is invalid"),
86 #[cfg(feature = "spiffe-auth")]
87 ClientErrorKind::Spiffe(error) => error.fmt(f),
88 }
89 }
90}
91
92pub type Result<T> = ::std::result::Result<T, Error>;