1use log::{debug, error, info, trace, warn};
3use xvc_config::error::Error as XvcConfigError;
4use xvc_ecs::error::Error as XvcEcsError;
5use xvc_walker::error::Error as XvcWalkerError;
6
7use std::ffi::OsString;
8use std::fmt::Debug;
9use std::io;
10use std::path::PathBuf;
11use std::sync::PoisonError;
12use thiserror::Error as ThisError;
13
14#[allow(missing_docs)]
15#[derive(ThisError, Debug)]
16pub enum Error {
17 #[error("Sorry. {0} is not implemented yet")]
18 Todo(&'static str),
19
20 #[error("General Xvc Core Error: {msg}")]
21 GeneralError { msg: String },
22
23 #[error("General Xvc Core Error: {source}")]
24 AnyhowError {
25 #[from]
26 source: anyhow::Error,
27 },
28
29 #[error("ECS Error: {source}")]
30 EcsError {
31 #[from]
32 source: XvcEcsError,
33 },
34 #[error("Walker Error: {source}")]
35 WalkerError {
36 #[from]
37 source: XvcWalkerError,
38 },
39
40 #[error("Config Error: {source}")]
41 ConfigError {
42 #[from]
43 source: XvcConfigError,
44 },
45
46 #[error("File System Walk Error: {error}")]
47 FSWalkerError { error: String },
48 #[error("Cannot find Xvc Root: {path}")]
49 CannotFindXvcRoot { path: PathBuf },
50 #[error("Cannot nest Xvc repositories: {path}")]
51 CannotNestXvcRepositories { path: PathBuf },
52 #[error("Regex Error: {source}")]
53 RegexError {
54 #[from]
55 source: regex::Error,
56 },
57 #[error("System Time Error: {source}")]
58 SystemTimeError {
59 #[from]
60 source: std::time::SystemTimeError,
61 },
62 #[error("[E1002] MsgPack Serialization Error: {source}")]
63 MsgPackDecodeError {
64 #[from]
65 source: rmp_serde::decode::Error,
66 },
67 #[error("[E1003] MsgPack Serialization Error: {source}")]
68 MsgPackEncodeError {
69 #[from]
70 source: rmp_serde::encode::Error,
71 },
72 #[error("[E1004] Json Serialization Error: {source}")]
73 JsonError {
74 #[from]
75 source: serde_json::Error,
76 },
77 #[error("TOML Serialization Error: {source}")]
78 TomlSerializationError {
79 #[from]
80 source: toml::ser::Error,
81 },
82
83 #[error("TOML Deserialization Error: {source}")]
84 TomlDeserializationError {
85 #[from]
86 source: toml::de::Error,
87 },
88
89 #[error("Yaml Error: {source}")]
90 YamlError {
91 #[from]
92 source: serde_yaml::Error,
93 },
94 #[error("Encountered NULL value in YAML map")]
95 YamlNullValueForKey { key: String },
96 #[error("I/O Error: {source}")]
97 IoError {
98 #[from]
99 source: io::Error,
100 },
101 #[error("Unicode/UTF-8 Error: {cause:?}")]
102 UnicodeError { cause: OsString },
103 #[error("Glob Error: {source}")]
104 GlobError {
105 #[from]
106 source: glob::GlobError,
107 },
108 #[error("Glob Pattern Error: {source}")]
110 GlobPatternError {
111 #[from]
112 source: glob::PatternError,
113 },
114 #[error("Path strip prefix error: {source}")]
115 StringPrefixError {
116 #[from]
117 source: std::path::StripPrefixError,
118 },
119
120 #[error("Request Error: {source}")]
121 ReqwestError {
122 #[from]
123 source: reqwest::Error,
124 },
125
126 #[error("Git Process Error: \nSTDOUT: {stdout}\nSTDERR: {stderr}")]
127 GitProcessError { stdout: String, stderr: String },
128
129 #[error("Crossbeam Send Error for Type: {t:?} {cause:?}")]
130 CrossbeamSendError { t: String, cause: String },
131 #[error("Relative Path Conversion Error: {source}")]
132 RelativePathError {
133 #[from]
134 source: relative_path::FromPathError,
135 },
136
137 #[error("Cannot Find Executable: {source}")]
138 WhichError {
139 #[from]
140 source: which::Error,
141 },
142
143 #[error("Process Exec Error: {source}")]
144 ProcessExecError {
145 #[from]
146 source: subprocess::PopenError,
147 },
148
149 #[error("Cannot find parent path")]
150 CannotFindParentPath { path: PathBuf },
151
152 #[error("Poison Error: {cause:?}")]
153 PoisonError { cause: String },
154
155 #[error("Gix Repository Error: {cause}")]
156 GixError { cause: String },
157
158 #[error("Gix References Error: {source}")]
159 GixReferencesError {
160 #[from]
161 source: gix::reference::iter::Error,
162 },
163
164 #[error("Gix Init Error: {source}")]
165 GixReferenceInitError {
166 #[from]
167 source: gix::reference::iter::init::Error,
168 },
169}
170
171impl<T> From<crossbeam_channel::SendError<T>> for Error
172where
173 T: Debug,
174{
175 fn from(e: crossbeam_channel::SendError<T>) -> Self {
176 Error::CrossbeamSendError {
177 t: format!("{:#?}", e.0),
178 cause: e.to_string(),
179 }
180 }
181}
182
183impl From<Box<dyn std::any::Any + Send>> for Error {
184 fn from(e: Box<dyn std::any::Any + Send>) -> Self {
185 Error::GeneralError {
186 msg: format!("{:?}", e),
187 }
188 }
189}
190
191impl<T: Debug> From<PoisonError<T>> for Error {
192 fn from(e: PoisonError<T>) -> Self {
193 Error::PoisonError {
194 cause: e.to_string(),
195 }
196 }
197}
198
199impl<T: Debug> From<&PoisonError<T>> for Error {
200 fn from(e: &PoisonError<T>) -> Self {
201 Error::PoisonError {
202 cause: e.to_string(),
203 }
204 }
205}
206
207impl Error {
208 pub fn debug(self) -> Self {
210 debug!("{}", self);
211 self
212 }
213 pub fn trace(self) -> Self {
215 trace!("{}", self);
216 self
217 }
218 pub fn warn(self) -> Self {
220 warn!("{}", self);
221 self
222 }
223 pub fn error(self) -> Self {
225 error!("{}", self);
226 self
227 }
228 pub fn info(self) -> Self {
230 info!("{}", self);
231 self
232 }
233 pub fn panic(self) -> Self {
235 panic!("{}", self);
236 }
237}
238
239pub type Result<T> = std::result::Result<T, Error>;