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