open_sesame/util/
error.rs1use std::path::PathBuf;
6
7#[derive(Debug, thiserror::Error)]
9pub enum Error {
10 #[error("Failed to connect to Wayland compositor")]
12 WaylandConnection(#[source] Box<dyn std::error::Error + Send + Sync>),
13
14 #[error("Required Wayland protocol not available: {protocol}")]
16 MissingProtocol {
17 protocol: &'static str,
19 },
20
21 #[error("Window not found: {identifier}")]
23 WindowNotFound {
24 identifier: String,
26 },
27
28 #[error("Failed to activate window: {0}")]
30 ActivationFailed(String),
31
32 #[error("Failed to parse configuration: {0}")]
34 ConfigParse(#[from] toml::de::Error),
35
36 #[error("Failed to read configuration file: {path}")]
38 ConfigRead {
39 path: PathBuf,
41 #[source]
43 source: std::io::Error,
44 },
45
46 #[error("Invalid configuration: {message}")]
48 ConfigValidation {
49 message: String,
51 },
52
53 #[error("Invalid color format: {value}")]
55 InvalidColor {
56 value: String,
58 },
59
60 #[error("Failed to create rendering surface")]
62 SurfaceCreation,
63
64 #[error("Invalid surface dimensions: {width}x{height}")]
66 InvalidDimensions {
67 width: u32,
69 height: u32,
71 },
72
73 #[error("Font not available")]
75 FontNotFound,
76
77 #[error("I/O error: {0}")]
79 Io(#[from] std::io::Error),
80
81 #[error("Failed to launch application: {command}")]
83 LaunchFailed {
84 command: String,
86 #[source]
88 source: std::io::Error,
89 },
90
91 #[error("{0}")]
93 Other(String),
94}
95
96pub type Result<T> = std::result::Result<T, Error>;
98
99impl Error {
100 pub fn other<E: std::fmt::Display>(error: E) -> Self {
102 Self::Other(error.to_string())
103 }
104
105 pub fn is_recoverable(&self) -> bool {
107 matches!(
108 self,
109 Error::WindowNotFound { .. }
110 | Error::ConfigValidation { .. }
111 | Error::InvalidColor { .. }
112 )
113 }
114}
115
116impl From<anyhow::Error> for Error {
118 fn from(err: anyhow::Error) -> Self {
119 Error::Other(err.to_string())
120 }
121}