1use atspi::error::AtspiError;
2use serde_plain::Error as SerdePlainError;
3use smartstring::alias::String as SmartString;
4use std::{error::Error, fmt, str::FromStr};
5
6#[derive(Debug)]
7pub enum OdiliaError {
8 AtspiError(AtspiError),
9 PrimitiveConversionError(AccessiblePrimitiveConversionError),
10 NoAttributeError(String),
11 SerdeError(SerdePlainError),
12 Zbus(zbus::Error),
13 ZbusFdo(zbus::fdo::Error),
14 Zvariant(zbus::zvariant::Error),
15 Cache(CacheError),
16 InfallibleConversion(std::convert::Infallible),
17 ConversionError(std::num::TryFromIntError),
18 Config(ConfigError),
19 PoisoningError,
20 Generic(String),
21}
22#[derive(Debug)]
23pub enum ConfigError {
24 Tini(tini::Error),
25 ValueNotFound,
26 PathNotFound,
27}
28impl From<tini::Error> for ConfigError {
29 fn from(t_err: tini::Error) -> Self {
30 Self::Tini(t_err)
31 }
32}
33impl std::fmt::Display for ConfigError {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 match self {
36 Self::Tini(t) => t.fmt(f),
37 Self::ValueNotFound => f.write_str("Vlaue not found in config file."),
38 Self::PathNotFound => {
39 f.write_str("The path for the config file was not found.")
40 }
41 }
42 }
43}
44impl std::error::Error for ConfigError {}
45#[derive(Debug)]
46pub enum CacheError {
47 NotAvailable,
48 NoItem,
49 NoLock,
50 TextBoundsError,
51}
52impl std::fmt::Display for CacheError {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 match self {
55 Self::NotAvailable => f.write_str("The cache has been dropped from memory. This never happens under normal circumstances, and should never happen. Please send a detailed bug report if this ever happens."),
56 Self::NoItem => f.write_str("No item in cache found."),
57 Self::NoLock => f.write_str("It was not possible to get a lock on this item from the cache."),
58 Self::TextBoundsError => f.write_str("The range asked for in a call to a get_string_*_offset function has invalid bounds."),
59 }
60 }
61}
62impl std::error::Error for CacheError {}
63impl Error for OdiliaError {}
64impl<T> From<std::sync::PoisonError<T>> for OdiliaError {
65 fn from(_: std::sync::PoisonError<T>) -> Self {
66 Self::PoisoningError
67 }
68}
69impl From<std::num::TryFromIntError> for OdiliaError {
70 fn from(fie: std::num::TryFromIntError) -> Self {
71 Self::ConversionError(fie)
72 }
73}
74impl From<zbus::fdo::Error> for OdiliaError {
75 fn from(spe: zbus::fdo::Error) -> Self {
76 Self::ZbusFdo(spe)
77 }
78}
79impl From<std::convert::Infallible> for OdiliaError {
80 fn from(infallible: std::convert::Infallible) -> Self {
81 Self::InfallibleConversion(infallible)
82 }
83}
84impl From<CacheError> for OdiliaError {
85 fn from(cache_error: CacheError) -> Self {
86 Self::Cache(cache_error)
87 }
88}
89impl From<zbus::Error> for OdiliaError {
90 fn from(spe: zbus::Error) -> Self {
91 Self::Zbus(spe)
92 }
93}
94impl From<zbus::zvariant::Error> for OdiliaError {
95 fn from(spe: zbus::zvariant::Error) -> Self {
96 Self::Zvariant(spe)
97 }
98}
99impl From<SerdePlainError> for OdiliaError {
100 fn from(spe: SerdePlainError) -> Self {
101 Self::SerdeError(spe)
102 }
103}
104impl From<AtspiError> for OdiliaError {
105 fn from(err: AtspiError) -> OdiliaError {
106 Self::AtspiError(err)
107 }
108}
109impl fmt::Display for OdiliaError {
110 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
111 write!(f, "{self:?}")
112 }
113}
114
115#[derive(Clone, Debug)]
116pub enum AccessiblePrimitiveConversionError {
117 ParseError(<i32 as FromStr>::Err),
118 ObjectConversionError(atspi::error::ObjectPathConversionError),
119 NoPathId,
120 InvalidPath,
121 NoFirstSectionOfSender,
122 NoSecondSectionOfSender,
123 NoSender,
124 ErrSender,
125}
126impl From<AccessiblePrimitiveConversionError> for OdiliaError {
127 fn from(apc_error: AccessiblePrimitiveConversionError) -> Self {
128 Self::PrimitiveConversionError(apc_error)
129 }
130}
131impl fmt::Display for AccessiblePrimitiveConversionError {
132 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
133 write!(f, "{self:?}")
134 }
135}
136impl std::error::Error for AccessiblePrimitiveConversionError {}
137impl From<atspi::error::ObjectPathConversionError> for AccessiblePrimitiveConversionError {
138 fn from(object_conversion_error: atspi::error::ObjectPathConversionError) -> Self {
139 Self::ObjectConversionError(object_conversion_error)
140 }
141}
142
143#[derive(Debug, Clone, thiserror::Error)]
144pub enum KeyFromStrError {
145 #[error("Empty key binding")]
146 EmptyString,
147 #[error("No key was provided")]
148 NoKey,
149 #[error("Empty key")]
150 EmptyKey,
151 #[error("Invalid key: {0:?}")]
152 InvalidKey(SmartString),
153 #[error("Invalid repeat: {0:?}")]
154 InvalidRepeat(SmartString),
155 #[error("Invalid modifier: {0:?}")]
156 InvalidModifier(SmartString),
157 #[error("Invalid mode: {0:?}")]
158 InvalidMode(SmartString),
159}
160
161#[derive(Debug, Clone, Copy, thiserror::Error)]
162pub enum ModeFromStrError {
163 #[error("Mode not found")]
164 ModeNameNotFound,
165}