#[derive(Debug, thiserror::Error)]
pub enum SeatError {
#[error("no Wayland session is available to proxy into")]
NoWaylandSession,
#[error("XDG_RUNTIME_DIR is not set; no runtime directory for the seat socket")]
MissingRuntimeDir,
#[error("could not create the agent seat socket: {0}")]
SocketCreate(String),
#[error("XWayland bridge failure: {0}")]
Xwayland(String),
#[error("XWayland authority failure: {0}")]
Xauth(String),
#[error("peer credential failure: {0}")]
PeerCredential(String),
#[error("capture failure: {0}")]
Capture(String),
#[error("input injection failure: {0}")]
Input(String),
#[error("process failure: {0}")]
Process(String),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("{0}")]
Custom(String),
}
impl From<String> for SeatError {
fn from(message: String) -> Self {
Self::Custom(message)
}
}
impl From<&str> for SeatError {
fn from(message: &str) -> Self {
Self::Custom(message.to_string())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn string_conversions_become_custom() {
let owned = SeatError::from(String::from("boom"));
assert!(matches!(&owned, SeatError::Custom(_)));
assert_eq!(owned.to_string(), "boom");
let borrowed = SeatError::from("boom");
assert!(matches!(&borrowed, SeatError::Custom(_)));
assert_eq!(borrowed.to_string(), "boom");
}
#[test]
fn io_errors_keep_their_message_and_chain() {
let inner = std::io::Error::other("disk");
let has_source = std::error::Error::source(&inner).is_some();
let error = SeatError::from(inner);
assert!(matches!(&error, SeatError::Io(_)));
assert!(error.to_string().contains("disk"));
assert_eq!(std::error::Error::source(&error).is_some(), has_source);
}
}