1use std::io;
4
5use aranya_daemon_api as api;
6use tarpc::client::RpcError;
7
8#[cfg(feature = "afc")]
9use crate::afc::Error as AfcError;
10
11pub type Result<T, E = Error> = core::result::Result<T, E>;
13
14#[derive(Debug, thiserror::Error)]
16#[non_exhaustive]
17pub enum Error {
18 #[error("IPC error")]
20 Ipc(#[from] IpcError),
21
22 #[error("daemon error")]
24 Aranya(#[from] AranyaError),
25
26 #[error("configuration error")]
28 Config(#[from] ConfigError),
29
30 #[cfg(feature = "afc")]
32 #[cfg_attr(docsrs, doc(cfg(feature = "afc")))]
33 #[error("AFC error")]
34 Afc(#[from] AfcError),
35
36 #[error(transparent)]
38 Bug(#[from] buggy::Bug),
39
40 #[error(transparent)]
42 Other(#[from] OtherError),
43}
44
45impl From<core::convert::Infallible> for Error {
46 fn from(value: core::convert::Infallible) -> Self {
47 match value {}
48 }
49}
50
51#[derive(Debug, thiserror::Error)]
53#[error(transparent)]
54pub struct OtherError {
55 #[from]
56 err: anyhow::Error,
57}
58
59pub(crate) fn other<E>(err: E) -> OtherError
60where
61 E: Into<anyhow::Error>,
62{
63 OtherError { err: err.into() }
64}
65
66#[derive(Debug, thiserror::Error)]
68#[error(transparent)]
69pub struct AranyaError {
70 #[from]
71 err: api::Error,
72}
73
74pub(crate) fn aranya_error(err: api::Error) -> Error {
75 Error::Aranya(err.into())
76}
77
78#[derive(Debug, thiserror::Error)]
80#[non_exhaustive]
81pub enum ConfigError {
82 #[error(transparent)]
84 InvalidArg(#[from] InvalidArg),
85}
86
87#[derive(Debug, thiserror::Error)]
89#[error("invalid argument `{arg}`: {reason}")]
90pub struct InvalidArg {
91 arg: &'static str,
92 reason: &'static str,
93}
94
95impl InvalidArg {
96 pub(crate) const fn new(arg: &'static str, reason: &'static str) -> Self {
97 Self { arg, reason }
98 }
99}
100
101#[derive(Debug, thiserror::Error)]
103#[error(transparent)]
104pub struct IpcError(#[from] pub(crate) IpcRepr);
105
106impl IpcError {
107 pub(crate) fn new<E>(err: E) -> Self
108 where
109 E: Into<IpcRepr>,
110 {
111 Self(err.into())
112 }
113}
114
115#[derive(Debug, thiserror::Error)]
116#[error(transparent)]
117pub(crate) enum IpcRepr {
118 InvalidArg(#[from] InvalidArg),
119 Io(#[from] io::Error),
120 Tarpc(#[from] RpcError),
121 Other(#[from] anyhow::Error),
122}