agent_seat_linux/
error.rs1#[derive(Debug, thiserror::Error)]
11pub enum SeatError {
12 #[error("no Wayland session is available to proxy into")]
15 NoWaylandSession,
16
17 #[error("XDG_RUNTIME_DIR is not set; no runtime directory for the seat socket")]
19 MissingRuntimeDir,
20
21 #[error("could not create the agent seat socket: {0}")]
23 SocketCreate(String),
24
25 #[error("XWayland bridge failure: {0}")]
27 Xwayland(String),
28
29 #[error("XWayland authority failure: {0}")]
31 Xauth(String),
32
33 #[error("peer credential failure: {0}")]
36 PeerCredential(String),
37
38 #[error("capture failure: {0}")]
40 Capture(String),
41
42 #[error("input injection failure: {0}")]
44 Input(String),
45
46 #[error("process failure: {0}")]
48 Process(String),
49
50 #[error(transparent)]
52 Io(#[from] std::io::Error),
53
54 #[error("{0}")]
56 Custom(String),
57}
58
59impl From<String> for SeatError {
60 fn from(message: String) -> Self {
61 Self::Custom(message)
62 }
63}
64
65impl From<&str> for SeatError {
66 fn from(message: &str) -> Self {
67 Self::Custom(message.to_string())
68 }
69}
70
71#[cfg(test)]
72mod tests {
73 use super::*;
74
75 #[test]
76 fn string_conversions_become_custom() {
77 let owned = SeatError::from(String::from("boom"));
78 assert!(matches!(&owned, SeatError::Custom(_)));
79 assert_eq!(owned.to_string(), "boom");
80
81 let borrowed = SeatError::from("boom");
82 assert!(matches!(&borrowed, SeatError::Custom(_)));
83 assert_eq!(borrowed.to_string(), "boom");
84 }
85
86 #[test]
87 fn io_errors_keep_their_message_and_chain() {
88 let inner = std::io::Error::other("disk");
90 let has_source = std::error::Error::source(&inner).is_some();
91 let error = SeatError::from(inner);
92 assert!(matches!(&error, SeatError::Io(_)));
93 assert!(error.to_string().contains("disk"));
94 assert_eq!(std::error::Error::source(&error).is_some(), has_source);
95 }
96}