1#[allow(clippy::module_name_repetitions)]
2#[derive(Debug)]
3#[non_exhaustive]
4pub enum AtspiError {
6 Conversion(&'static str),
8
9 CacheVariantMismatch,
11
12 MemberMatch(String),
14
15 InterfaceMatch(String),
17
18 UnknownBusSignature(String),
20
21 UnknownInterface,
23
24 MissingInterface,
26
27 MissingMember,
29
30 MissingSignature,
32
33 UnknownRole(u32),
35
36 MissingName,
38
39 UnknownSignal,
41
42 Owned(String),
44
45 Zbus(String),
47
48 ZBusNames(zbus_names::Error),
50
51 Zvariant(zvariant::Error),
53
54 ParseError(&'static str),
56
57 PathConversionError(ObjectPathConversionError),
59
60 IO(std::io::Error),
62
63 IntConversionError(std::num::TryFromIntError),
65
66 Infallible,
68}
69
70impl std::error::Error for AtspiError {}
71
72impl std::fmt::Display for AtspiError {
73 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74 match self {
75 Self::Conversion(e) => f.write_str(&format!("atspi: conversion failure: {e}")),
76 Self::MemberMatch(e) => {
77 f.write_str(format!("atspi: member mismatch in conversion: {e}").as_str())
78 }
79 Self::InterfaceMatch(e) => {
80 f.write_str(format!("atspi: interface mismatch in conversion: {e}").as_str())
81 }
82 Self::UnknownBusSignature(e) => {
83 f.write_str(format!("atspi: Unknown bus body signature: {e:?}").as_str())
84 }
85 Self::UnknownInterface => f.write_str("Unknown interface."),
86 Self::MissingInterface => f.write_str("Missing interface."),
87 Self::MissingMember => f.write_str("Missing member."),
88 Self::MissingSignature => f.write_str("Missing signature."),
89 Self::UnknownRole(e) => f.write_str(&format!("atspi: Unknown role: {e}")),
90 Self::UnknownSignal => f.write_str("atspi: Unknown signal"),
91 Self::CacheVariantMismatch => f.write_str("atspi: Cache variant mismatch"),
92 Self::Owned(e) => f.write_str(&format!("atspi: other error: {e}")),
93 Self::Zbus(e) => f.write_str(&format!("ZBus Error: {e}")),
94 Self::Zvariant(e) => f.write_str(&format!("Zvariant error: {e}")),
95 Self::ZBusNames(e) => f.write_str(&format!("ZBus_names Error: {e}")),
96 Self::ParseError(e) => f.write_str(e),
97 Self::PathConversionError(e) => {
98 f.write_str(&format!("ID cannot be extracted from the path: {e}"))
99 }
100 Self::IO(e) => f.write_str(&format!("std IO Error: {e}")),
101 Self::IntConversionError(e) => f.write_str(&format!("Integer conversion error: {e}")),
102 Self::MissingName => f.write_str("Missing name for a bus."),
103 Self::Infallible => {
104 f.write_str("Infallible; only to trick the compiler. This should never happen.")
105 }
106 }
107 }
108}
109
110impl From<std::convert::Infallible> for AtspiError {
111 fn from(_e: std::convert::Infallible) -> Self {
112 Self::Infallible
113 }
114}
115impl From<std::num::TryFromIntError> for AtspiError {
116 fn from(e: std::num::TryFromIntError) -> Self {
117 Self::IntConversionError(e)
118 }
119}
120
121#[cfg(feature = "zbus")]
122impl From<zbus::fdo::Error> for AtspiError {
123 fn from(e: zbus::fdo::Error) -> Self {
124 Self::Zbus(format!("{e:?}"))
125 }
126}
127
128#[cfg(feature = "zbus")]
129impl From<zbus::Error> for AtspiError {
130 fn from(e: zbus::Error) -> Self {
131 Self::Zbus(format!("{e:?}"))
132 }
133}
134
135impl From<zbus_names::Error> for AtspiError {
136 fn from(e: zbus_names::Error) -> Self {
137 Self::ZBusNames(e)
138 }
139}
140
141impl From<zvariant::Error> for AtspiError {
142 fn from(e: zvariant::Error) -> Self {
143 Self::Zvariant(e)
144 }
145}
146
147impl From<std::io::Error> for AtspiError {
148 fn from(e: std::io::Error) -> Self {
149 Self::IO(e)
150 }
151}
152
153impl From<ObjectPathConversionError> for AtspiError {
154 fn from(e: ObjectPathConversionError) -> AtspiError {
155 Self::PathConversionError(e)
156 }
157}
158
159#[allow(clippy::module_name_repetitions)]
160#[derive(Clone, Debug)]
161pub enum ObjectPathConversionError {
162 NoIdAvailable,
163 ParseError(<i64 as std::str::FromStr>::Err),
164}
165impl std::fmt::Display for ObjectPathConversionError {
166 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
167 match self {
168 Self::NoIdAvailable => f.write_str("No ID available in the path."),
169 Self::ParseError(e) => f.write_str(&format!("Failure to parse: {e}")),
170 }
171 }
172}
173impl std::error::Error for ObjectPathConversionError {}