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