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 KindMatch(String),
20
21 InterfaceNotAvailable(&'static str),
23
24 SignatureMatch(String),
26
27 UnknownInterface,
29
30 MissingInterface,
32
33 MissingMember,
35
36 MissingPath,
38
39 UnknownRole(u32),
41
42 MissingName,
44
45 UnknownSignal,
47
48 Owned(String),
50
51 NullRef(&'static str),
53
54 Zbus(String),
56
57 ZBusNames(zbus_names::Error),
59
60 Zvariant(zvariant::Error),
62
63 ParseError(&'static str),
65
66 PathConversionError(ObjectPathConversionError),
68
69 IO(std::io::Error),
71
72 IntConversionError(std::num::TryFromIntError),
74
75 Infallible,
77}
78
79impl std::error::Error for AtspiError {}
80
81impl std::fmt::Display for AtspiError {
82 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83 match self {
84 Self::Conversion(e) => f.write_str(&format!("atspi: conversion failure: {e}")),
85 Self::MemberMatch(e) => {
86 f.write_str("atspi: member mismatch in conversion: ")?;
87 e.fmt(f)
88 }
89 Self::InterfaceMatch(e) => {
90 f.write_str("atspi: interface mismatch in conversion: ")?;
91 e.fmt(f)
92 }
93 Self::KindMatch(e) => {
94 f.write_str(format!("atspi: kind mismatch in conversion: {e}").as_str())
95 }
96 Self::SignatureMatch(e) => {
97 f.write_str(format!("atspi: body signature mismatch in conversion: {e:?}").as_str())
98 }
99 Self::InterfaceNotAvailable(e) => {
100 f.write_str(format!("atspi: interface not available: {e}").as_str())
101 }
102 Self::UnknownInterface => f.write_str("Unknown interface."),
103 Self::MissingInterface => f.write_str("Missing interface."),
104 Self::MissingMember => f.write_str("Missing member."),
105 Self::MissingPath => f.write_str("Missing path."),
106 Self::UnknownRole(e) => {
107 f.write_str("atspi: Unknown role: ")?;
108 e.fmt(f)
109 }
110 Self::UnknownSignal => f.write_str("atspi: Unknown signal"),
111 Self::CacheVariantMismatch => f.write_str("atspi: Cache variant mismatch"),
112 Self::Owned(e) => {
113 f.write_str("atspi: other error: ")?;
114 e.fmt(f)
115 }
116 Self::NullRef(e) => {
117 f.write_str("atspi: null reference: ")?;
118 f.write_str(e)
119 }
120 Self::Zbus(e) => {
121 f.write_str("ZBus Error: ")?;
122 e.fmt(f)
123 }
124 Self::Zvariant(e) => {
125 f.write_str("Zvariant error: ")?;
126 e.fmt(f)
127 }
128 Self::ZBusNames(e) => {
129 f.write_str("ZBus_names Error: ")?;
130 e.fmt(f)
131 }
132 Self::ParseError(e) => f.write_str(e),
133 Self::PathConversionError(e) => {
134 f.write_str("ID cannot be extracted from the path: ")?;
135 e.fmt(f)
136 }
137 Self::IO(e) => {
138 f.write_str("std IO Error: ")?;
139 e.fmt(f)
140 }
141 Self::IntConversionError(e) => {
142 f.write_str("Integer conversion error: ")?;
143 e.fmt(f)
144 }
145 Self::MissingName => f.write_str("Missing name for a bus."),
146 Self::Infallible => {
147 f.write_str("Infallible; only to trick the compiler. This should never happen.")
148 }
149 }
150 }
151}
152
153impl From<std::convert::Infallible> for AtspiError {
154 fn from(_e: std::convert::Infallible) -> Self {
155 Self::Infallible
156 }
157}
158impl From<std::num::TryFromIntError> for AtspiError {
159 fn from(e: std::num::TryFromIntError) -> Self {
160 Self::IntConversionError(e)
161 }
162}
163
164#[cfg(feature = "zbus")]
165impl From<zbus::fdo::Error> for AtspiError {
166 fn from(e: zbus::fdo::Error) -> Self {
167 Self::Zbus(format!("{e:?}"))
168 }
169}
170
171#[cfg(feature = "zbus")]
172impl From<zbus::Error> for AtspiError {
173 fn from(e: zbus::Error) -> Self {
174 Self::Zbus(format!("{e:?}"))
175 }
176}
177
178impl From<zbus_names::Error> for AtspiError {
179 fn from(e: zbus_names::Error) -> Self {
180 Self::ZBusNames(e)
181 }
182}
183
184impl From<zvariant::Error> for AtspiError {
185 fn from(e: zvariant::Error) -> Self {
186 Self::Zvariant(e)
187 }
188}
189
190impl From<std::io::Error> for AtspiError {
191 fn from(e: std::io::Error) -> Self {
192 Self::IO(e)
193 }
194}
195
196impl From<ObjectPathConversionError> for AtspiError {
197 fn from(e: ObjectPathConversionError) -> AtspiError {
198 Self::PathConversionError(e)
199 }
200}
201
202#[allow(clippy::module_name_repetitions)]
203#[derive(Clone, Debug)]
204pub enum ObjectPathConversionError {
205 NoIdAvailable,
206 ParseError(<i64 as std::str::FromStr>::Err),
207}
208impl std::fmt::Display for ObjectPathConversionError {
209 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
210 match self {
211 Self::NoIdAvailable => f.write_str("No ID available in the path."),
212 Self::ParseError(e) => {
213 f.write_str("Failure to parse: ")?;
214 e.fmt(f)
215 }
216 }
217 }
218}
219impl std::error::Error for ObjectPathConversionError {}