1#[allow(clippy::module_name_repetitions)]
2#[derive(Debug)]
3#[non_exhaustive]
4/// An error type that can describe atspi and `std` and different `zbus` errors.
5pub enum AtspiError {
6/// Converting one type into another failure
7Conversion(&'static str),
89/// When testing on either variant, we might find the we are not interested in.
10CacheVariantMismatch,
1112/// On specific types, if the event / message member does not match the Event's name.
13MemberMatch(String),
1415/// On specific types, if the event / message member does not match the Event's name.
16InterfaceMatch(String),
1718/// To indicate a match or equality test on a signal body signature failed.
19UnknownBusSignature(String),
2021/// When matching on an unknown interface
22UnknownInterface,
2324/// No interface on event.
25MissingInterface,
2627/// No member on event.
28MissingMember,
2930/// No Signature.
31MissingSignature,
3233/// When matching on an unknown role
34UnknownRole(u32),
3536/// No name on bus.
37MissingName,
3839/// The signal that was encountered is unknown.
40UnknownSignal,
4142/// Other errors.
43Owned(String),
4445/// A `zbus` or `zbus::Fdo` error. variant.
46Zbus(String),
4748/// A `zbus_names` error variant
49ZBusNames(zbus_names::Error),
5051/// A `zbus_names` error variant
52Zvariant(zvariant::Error),
5354/// Failed to parse a string into an enum variant
55ParseError(&'static str),
5657/// Failed to get the ID of a path.
58PathConversionError(ObjectPathConversionError),
5960/// Std i/o error variant.
61IO(std::io::Error),
6263/// Failed to convert an integer into another type of integer (usually i32 -> usize).
64IntConversionError(std::num::TryFromIntError),
6566/// An infallible error; this is just something to satisfy the compiler.
67Infallible,
68}
6970impl std::error::Error for AtspiError {}
7172impl std::fmt::Display for AtspiError {
73fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74match self {
75Self::Conversion(e) => f.write_str(&format!("atspi: conversion failure: {e}")),
76Self::MemberMatch(e) => {
77 f.write_str(format!("atspi: member mismatch in conversion: {e}").as_str())
78 }
79Self::InterfaceMatch(e) => {
80 f.write_str(format!("atspi: interface mismatch in conversion: {e}").as_str())
81 }
82Self::UnknownBusSignature(e) => {
83 f.write_str(format!("atspi: Unknown bus body signature: {e:?}").as_str())
84 }
85Self::UnknownInterface => f.write_str("Unknown interface."),
86Self::MissingInterface => f.write_str("Missing interface."),
87Self::MissingMember => f.write_str("Missing member."),
88Self::MissingSignature => f.write_str("Missing signature."),
89Self::UnknownRole(e) => f.write_str(&format!("atspi: Unknown role: {e}")),
90Self::UnknownSignal => f.write_str("atspi: Unknown signal"),
91Self::CacheVariantMismatch => f.write_str("atspi: Cache variant mismatch"),
92Self::Owned(e) => f.write_str(&format!("atspi: other error: {e}")),
93Self::Zbus(e) => f.write_str(&format!("ZBus Error: {e}")),
94Self::Zvariant(e) => f.write_str(&format!("Zvariant error: {e}")),
95Self::ZBusNames(e) => f.write_str(&format!("ZBus_names Error: {e}")),
96Self::ParseError(e) => f.write_str(e),
97Self::PathConversionError(e) => {
98 f.write_str(&format!("ID cannot be extracted from the path: {e}"))
99 }
100Self::IO(e) => f.write_str(&format!("std IO Error: {e}")),
101Self::IntConversionError(e) => f.write_str(&format!("Integer conversion error: {e}")),
102Self::MissingName => f.write_str("Missing name for a bus."),
103Self::Infallible => {
104 f.write_str("Infallible; only to trick the compiler. This should never happen.")
105 }
106 }
107 }
108}
109110impl From<std::convert::Infallible> for AtspiError {
111fn from(_e: std::convert::Infallible) -> Self {
112Self::Infallible
113 }
114}
115impl From<std::num::TryFromIntError> for AtspiError {
116fn from(e: std::num::TryFromIntError) -> Self {
117Self::IntConversionError(e)
118 }
119}
120121#[cfg(feature = "zbus")]
122impl From<zbus::fdo::Error> for AtspiError {
123fn from(e: zbus::fdo::Error) -> Self {
124Self::Zbus(format!("{e:?}"))
125 }
126}
127128#[cfg(feature = "zbus")]
129impl From<zbus::Error> for AtspiError {
130fn from(e: zbus::Error) -> Self {
131Self::Zbus(format!("{e:?}"))
132 }
133}
134135impl From<zbus_names::Error> for AtspiError {
136fn from(e: zbus_names::Error) -> Self {
137Self::ZBusNames(e)
138 }
139}
140141impl From<zvariant::Error> for AtspiError {
142fn from(e: zvariant::Error) -> Self {
143Self::Zvariant(e)
144 }
145}
146147impl From<std::io::Error> for AtspiError {
148fn from(e: std::io::Error) -> Self {
149Self::IO(e)
150 }
151}
152153impl From<ObjectPathConversionError> for AtspiError {
154fn from(e: ObjectPathConversionError) -> AtspiError {
155Self::PathConversionError(e)
156 }
157}
158159#[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 {
166fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
167match self {
168Self::NoIdAvailable => f.write_str("No ID available in the path."),
169Self::ParseError(e) => f.write_str(&format!("Failure to parse: {e}")),
170 }
171 }
172}
173impl std::error::Error for ObjectPathConversionError {}