#[allow(clippy::module_name_repetitions)]
#[derive(Debug)]
#[non_exhaustive]
pub enum AtspiError {
Conversion(&'static str),
CacheVariantMismatch,
MemberMatch(String),
InterfaceMatch(String),
UnknownBusSignature(String),
UnknownInterface,
MissingInterface,
MissingMember,
UnknownRole(u32),
MissingName,
UnknownSignal,
Owned(String),
Zbus(String),
ZBusNames(zbus_names::Error),
Zvariant(zvariant::Error),
ParseError(&'static str),
PathConversionError(ObjectPathConversionError),
IO(std::io::Error),
IntConversionError(std::num::TryFromIntError),
Infallible,
}
impl std::error::Error for AtspiError {}
impl std::fmt::Display for AtspiError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Conversion(e) => f.write_str(&format!("atspi: conversion failure: {e}")),
Self::MemberMatch(e) => {
f.write_str(format!("atspi: member mismatch in conversion: {e}").as_str())
}
Self::InterfaceMatch(e) => {
f.write_str(format!("atspi: interface mismatch in conversion: {e}").as_str())
}
Self::UnknownBusSignature(e) => {
f.write_str(format!("atspi: Unknown bus body signature: {e:?}").as_str())
}
Self::UnknownInterface => f.write_str("Unknown interface."),
Self::MissingInterface => f.write_str("Missing interface."),
Self::MissingMember => f.write_str("Missing member."),
Self::UnknownRole(e) => f.write_str(&format!("atspi: Unknown role: {e}")),
Self::UnknownSignal => f.write_str("atspi: Unknown signal"),
Self::CacheVariantMismatch => f.write_str("atspi: Cache variant mismatch"),
Self::Owned(e) => f.write_str(&format!("atspi: other error: {e}")),
Self::Zbus(e) => f.write_str(&format!("ZBus Error: {e}")),
Self::Zvariant(e) => f.write_str(&format!("Zvariant error: {e}")),
Self::ZBusNames(e) => f.write_str(&format!("ZBus_names Error: {e}")),
Self::ParseError(e) => f.write_str(e),
Self::PathConversionError(e) => {
f.write_str(&format!("ID cannot be extracted from the path: {e}"))
}
Self::IO(e) => f.write_str(&format!("std IO Error: {e}")),
Self::IntConversionError(e) => f.write_str(&format!("Integer conversion error: {e}")),
Self::MissingName => f.write_str("Missing name for a bus."),
Self::Infallible => {
f.write_str("Infallible; only to trick the compiler. This should never happen.")
}
}
}
}
impl From<std::convert::Infallible> for AtspiError {
fn from(_e: std::convert::Infallible) -> Self {
Self::Infallible
}
}
impl From<std::num::TryFromIntError> for AtspiError {
fn from(e: std::num::TryFromIntError) -> Self {
Self::IntConversionError(e)
}
}
#[cfg(feature = "zbus")]
impl From<zbus::fdo::Error> for AtspiError {
fn from(e: zbus::fdo::Error) -> Self {
Self::Zbus(format!("{e:?}"))
}
}
#[cfg(feature = "zbus")]
impl From<zbus::Error> for AtspiError {
fn from(e: zbus::Error) -> Self {
Self::Zbus(format!("{e:?}"))
}
}
impl From<zbus_names::Error> for AtspiError {
fn from(e: zbus_names::Error) -> Self {
Self::ZBusNames(e)
}
}
impl From<zvariant::Error> for AtspiError {
fn from(e: zvariant::Error) -> Self {
Self::Zvariant(e)
}
}
impl From<std::io::Error> for AtspiError {
fn from(e: std::io::Error) -> Self {
Self::IO(e)
}
}
impl From<ObjectPathConversionError> for AtspiError {
fn from(e: ObjectPathConversionError) -> AtspiError {
Self::PathConversionError(e)
}
}
#[allow(clippy::module_name_repetitions)]
#[derive(Clone, Debug)]
pub enum ObjectPathConversionError {
NoIdAvailable,
ParseError(<i64 as std::str::FromStr>::Err),
}
impl std::fmt::Display for ObjectPathConversionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoIdAvailable => f.write_str("No ID available in the path."),
Self::ParseError(e) => f.write_str(&format!("Failure to parse: {e}")),
}
}
}
impl std::error::Error for ObjectPathConversionError {}