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