1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5 Zbus(zbus::Error),
6 Fdo(zbus::fdo::Error),
7 Json(serde_json::Error),
8 UserInputSlotMismatch,
10 BackendNotReady,
11 MissingUserCredentials,
12}
13
14impl PartialEq for Error {
15 fn eq(&self, other: &Self) -> bool {
16 match (self, other) {
17 (Error::Zbus(_), Error::Zbus(_)) => true,
18 (Error::Json(_), Error::Json(_)) => true,
19 (Error::UserInputSlotMismatch, Error::UserInputSlotMismatch) => true,
20 (Error::BackendNotReady, Error::BackendNotReady) => true,
21 (Error::MissingUserCredentials, Error::MissingUserCredentials) => true,
22 (_, _) => false,
23 }
24 }
25}
26
27impl From<zbus::Error> for Error {
28 fn from(err: zbus::Error) -> Self {
29 Self::Zbus(err)
30 }
31}
32
33impl From<zbus::fdo::Error> for Error {
34 fn from(err: zbus::fdo::Error) -> Self {
35 Self::Fdo(err)
36 }
37}
38
39impl From<serde_json::Error> for Error {
40 fn from(err: serde_json::Error) -> Self {
41 Self::Json(err)
42 }
43}
44
45impl fmt::Display for Error {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 match self {
48 Error::Zbus(err) => write!(f, "D-Bus Error: {:?}", err),
49 Error::Fdo(err) => write!(f, "D-Bus Error: {:?}", err),
50 Error::Json(err) => write!(f, "JSON Error: {}", err),
51 Error::UserInputSlotMismatch => write!(f, "Mismatch in User Input Queue Slot"),
52 Error::BackendNotReady => write!(f, "Backend VPN process is not ready"),
53 Error::MissingUserCredentials => write!(f, "Missing user credentials"),
54 }
55 }
56}