1use log::{debug, error, info, trace, warn};
3use std::hash::Hash;
4use thiserror::Error as ThisError;
5
6#[allow(missing_docs)]
7#[derive(ThisError, Debug)]
8pub enum Error {
10 #[error("General Xvc Walker Error: {source}")]
11 AnyhowError {
12 #[from]
13 source: anyhow::Error,
14 },
15 #[error("Crossbeam Send Error for Type: {t:?} {cause:?}")]
16 CrossbeamSendError { t: String, cause: String },
17
18 #[error("Ignore rules poisoned")]
19 LockPoisonError { t: String, cause: String },
20
21 #[error("File System Notify Error: {source:?}")]
22 NotifyError {
23 #[from]
24 source: notify::Error,
25 },
26
27 #[error("I/O Error: {source}")]
28 IoError {
29 #[from]
30 source: std::io::Error,
31 },
32
33 #[error("Cannot Merge Empty Ignore Rules")]
34 CannotMergeEmptyIgnoreRules,
35}
36
37impl Hash for Error {
38 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
39 format!("{}", self).hash(state);
40 }
41}
42
43impl PartialEq for Error {
44 fn eq(&self, other: &Self) -> bool {
45 format!("{}", self).eq(&format!("{}", other))
46 }
47}
48
49impl<T> From<crossbeam_channel::SendError<T>> for Error
50where
51 T: std::fmt::Debug,
52{
53 fn from(e: crossbeam_channel::SendError<T>) -> Self {
54 Error::CrossbeamSendError {
55 t: format!("{:#?}", e.0),
56 cause: e.to_string(),
57 }
58 }
59}
60impl<T> From<std::sync::PoisonError<T>> for Error
61where
62 T: std::fmt::Debug,
63{
64 fn from(e: std::sync::PoisonError<T>) -> Self {
65 Error::LockPoisonError {
66 t: format!("{:#?}", e),
67 cause: e.to_string(),
68 }
69 }
70}
71
72impl Error {
73 pub fn debug(self) -> Self {
75 debug!("{}", self);
76 self
77 }
78 pub fn trace(self) -> Self {
80 trace!("{}", self);
81 self
82 }
83 pub fn warn(self) -> Self {
85 warn!("{}", self);
86 self
87 }
88 pub fn error(self) -> Self {
90 error!("{}", self);
91 self
92 }
93 pub fn info(self) -> Self {
95 info!("{}", self);
96 self
97 }
98 pub fn panic(self) -> Self {
100 panic!("{}", self);
101 }
102}
103
104pub type Result<T> = std::result::Result<T, Error>;