1use log::{debug, error, info, trace, warn};
3use xvc_core::{XvcConfigError, XvcEcsError, XvcWalkerError};
4
5use std::fmt::Debug;
6use std::io;
7use std::path::PathBuf;
8use std::time::SystemTimeError;
9use thiserror::Error as ThisError;
10
11#[allow(missing_docs)]
13#[derive(ThisError, Debug)]
14pub enum Error {
15 #[error("Sorry. {0} is not implemented yet")]
16 Todo(&'static str),
17 #[error("{source}")]
18 AnyhowError {
19 #[from]
20 source: anyhow::Error,
21 },
22 #[error("Cannot find {xvc_path} in cache: {cache_path}")]
23 CannotFindFileInCache {
24 xvc_path: String,
25 cache_path: String,
26 },
27 #[error("File not found: {path}")]
28 FileNotFound { path: PathBuf },
29 #[error("Internal Error: {message}")]
30 InternalError { message: String },
31 #[error("Walker Error: {source}")]
32 WalkerError {
33 #[from]
34 source: XvcWalkerError,
35 },
36 #[error("Ecs Error: {source}")]
37 EcsError {
38 #[from]
39 source: XvcEcsError,
40 },
41 #[error("Storage Error: {source}")]
42 StorageError {
43 #[from]
44 source: xvc_storage::error::Error,
45 },
46 #[error("Target is ignored, please unignore in .xvcignore: {path}")]
47 TargetIgnored { path: String },
48
49 #[error("[E2004] Requires xvc repository.")]
50 RequiresXvcRepository,
51
52 #[error("Xvc Core Error: {source}")]
53 XvcCoreError {
54 #[from]
55 source: xvc_core::error::Error,
56 },
57 #[error("Xvc Config Error: {source}")]
58 XvcConfigError {
59 #[from]
60 source: XvcConfigError,
61 },
62 #[error("I/O Error: {source}")]
63 IoError {
64 #[from]
65 source: io::Error,
66 },
67 #[error("Enum Parsing Error")]
68 StrumError {
69 #[from]
70 source: strum::ParseError,
71 },
72 #[error("Crossbeam Send Error for Type: {t:?} {cause:?}")]
73 CrossbeamSendError { t: String, cause: String },
74
75 #[error("Strip Prefix Error")]
76 StripPrefixError {
77 #[from]
78 source: std::path::StripPrefixError,
79 },
80 #[error("Relative Path Strip Prefix Error: {:?}", e)]
81 RelativeStripPrefixError { e: relative_path::StripPrefixError },
82
83 #[error("System time error")]
84 SystemTimeError {
85 #[from]
86 source: SystemTimeError,
87 },
88 #[error("Xvc does not support content digest for symlink: {path}")]
89 ContentDigestNotSupported { path: PathBuf },
90
91 #[error("Poisoned Locks: {t} {cause}")]
92 LockPoisonError { t: String, cause: String },
93
94 #[error("Multiple files found to share")]
95 MultipleFilesToShare,
96
97 #[error("No files found to share")]
98 NoFilesToShare,
99
100 #[error("Error parsing the duration")]
101 DurationError {
102 #[from]
103 source: humantime::DurationError,
104 },
105
106 #[error("{message}: {files}")]
107 SourcesHaveChanged { message: String, files: String },
108}
109
110impl<T> From<crossbeam_channel::SendError<T>> for Error
111where
112 T: Debug,
113{
114 fn from(e: crossbeam_channel::SendError<T>) -> Self {
115 Error::CrossbeamSendError {
116 t: format!("{:#?}", e.0),
117 cause: e.to_string(),
118 }
119 }
120}
121
122impl<T> From<std::sync::PoisonError<T>> for Error
123where
124 T: std::fmt::Debug,
125{
126 fn from(e: std::sync::PoisonError<T>) -> Self {
127 Error::LockPoisonError {
128 t: format!("{:#?}", e),
129 cause: e.to_string(),
130 }
131 }
132}
133
134impl Error {
135 pub fn debug(self) -> Self {
137 debug!("{}", self);
138 self
139 }
140 pub fn trace(self) -> Self {
142 trace!("{}", self);
143 self
144 }
145
146 pub fn warn(self) -> Self {
148 warn!("{}", self);
149 self
150 }
151 pub fn error(self) -> Self {
153 error!("{}", self);
154 self
155 }
156 pub fn info(self) -> Self {
158 info!("{}", self);
159 self
160 }
161 pub fn panic(self) -> Self {
163 panic!("{}", self);
164 }
165}
166
167pub type Result<T> = std::result::Result<T, Error>;