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/// When matching on an unknown role
31UnknownRole(u32),
3233/// No name on bus.
34MissingName,
3536/// The signal that was encountered is unknown.
37UnknownSignal,
3839/// Other errors.
40Owned(String),
4142/// A `zbus` or `zbus::Fdo` error. variant.
43Zbus(String),
4445/// A `zbus_names` error variant
46ZBusNames(zbus_names::Error),
4748/// A `zbus_names` error variant
49Zvariant(zvariant::Error),
5051/// Failed to parse a string into an enum variant
52ParseError(&'static str),
5354/// Failed to get the ID of a path.
55PathConversionError(ObjectPathConversionError),
5657/// Std i/o error variant.
58IO(std::io::Error),
5960/// Failed to convert an integer into another type of integer (usually i32 -> usize).
61IntConversionError(std::num::TryFromIntError),
6263/// An infallible error; this is just something to satisfy the compiler.
64Infallible,
65}
6667impl std::error::Error for AtspiError {}
6869impl std::fmt::Display for AtspiError {
70fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71match self {
72Self::Conversion(e) => f.write_str(&format!("atspi: conversion failure: {e}")),
73Self::MemberMatch(e) => {
74 f.write_str(format!("atspi: member mismatch in conversion: {e}").as_str())
75 }
76Self::InterfaceMatch(e) => {
77 f.write_str(format!("atspi: interface mismatch in conversion: {e}").as_str())
78 }
79Self::UnknownBusSignature(e) => {
80 f.write_str(format!("atspi: Unknown bus body signature: {e:?}").as_str())
81 }
82Self::UnknownInterface => f.write_str("Unknown interface."),
83Self::MissingInterface => f.write_str("Missing interface."),
84Self::MissingMember => f.write_str("Missing member."),
85Self::UnknownRole(e) => f.write_str(&format!("atspi: Unknown role: {e}")),
86Self::UnknownSignal => f.write_str("atspi: Unknown signal"),
87Self::CacheVariantMismatch => f.write_str("atspi: Cache variant mismatch"),
88Self::Owned(e) => f.write_str(&format!("atspi: other error: {e}")),
89Self::Zbus(e) => f.write_str(&format!("ZBus Error: {e}")),
90Self::Zvariant(e) => f.write_str(&format!("Zvariant error: {e}")),
91Self::ZBusNames(e) => f.write_str(&format!("ZBus_names Error: {e}")),
92Self::ParseError(e) => f.write_str(e),
93Self::PathConversionError(e) => {
94 f.write_str(&format!("ID cannot be extracted from the path: {e}"))
95 }
96Self::IO(e) => f.write_str(&format!("std IO Error: {e}")),
97Self::IntConversionError(e) => f.write_str(&format!("Integer conversion error: {e}")),
98Self::MissingName => f.write_str("Missing name for a bus."),
99Self::Infallible => {
100 f.write_str("Infallible; only to trick the compiler. This should never happen.")
101 }
102 }
103 }
104}
105106impl From<std::convert::Infallible> for AtspiError {
107fn from(_e: std::convert::Infallible) -> Self {
108Self::Infallible
109 }
110}
111impl From<std::num::TryFromIntError> for AtspiError {
112fn from(e: std::num::TryFromIntError) -> Self {
113Self::IntConversionError(e)
114 }
115}
116117#[cfg(feature = "zbus")]
118impl From<zbus::fdo::Error> for AtspiError {
119fn from(e: zbus::fdo::Error) -> Self {
120Self::Zbus(format!("{e:?}"))
121 }
122}
123124#[cfg(feature = "zbus")]
125impl From<zbus::Error> for AtspiError {
126fn from(e: zbus::Error) -> Self {
127Self::Zbus(format!("{e:?}"))
128 }
129}
130131impl From<zbus_names::Error> for AtspiError {
132fn from(e: zbus_names::Error) -> Self {
133Self::ZBusNames(e)
134 }
135}
136137impl From<zvariant::Error> for AtspiError {
138fn from(e: zvariant::Error) -> Self {
139Self::Zvariant(e)
140 }
141}
142143impl From<std::io::Error> for AtspiError {
144fn from(e: std::io::Error) -> Self {
145Self::IO(e)
146 }
147}
148149impl From<ObjectPathConversionError> for AtspiError {
150fn from(e: ObjectPathConversionError) -> AtspiError {
151Self::PathConversionError(e)
152 }
153}
154155#[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 {
162fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
163match self {
164Self::NoIdAvailable => f.write_str("No ID available in the path."),
165Self::ParseError(e) => f.write_str(&format!("Failure to parse: {e}")),
166 }
167 }
168}
169impl std::error::Error for ObjectPathConversionError {}