use thiserror::Error;
#[derive(Debug, Error)]
pub enum DaemonError {
#[error("notify watcher error: {0}")]
Notify(#[from] notify_debouncer_full::notify::Error),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn daemon_error_notify_display() {
let err = DaemonError::Notify(notify_debouncer_full::notify::Error::path_not_found());
let msg = err.to_string();
assert!(msg.contains("notify watcher error"), "got: {msg}");
}
#[test]
fn daemon_error_io_display() {
let err = DaemonError::Io(std::io::Error::other("disk full"));
let msg = err.to_string();
assert!(msg.contains("io error"), "got: {msg}");
assert!(msg.contains("disk full"), "got: {msg}");
}
#[test]
fn daemon_error_debug_includes_variant() {
let err = DaemonError::Io(std::io::Error::other("x"));
let s = format!("{err:?}");
assert!(s.contains("Io"), "got: {s}");
}
#[test]
fn daemon_error_from_io_error() {
let io_err = std::io::Error::other("test");
let err: DaemonError = io_err.into();
assert!(matches!(err, DaemonError::Io(_)));
}
#[test]
fn daemon_error_is_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<DaemonError>();
}
}