1use log::{debug, error, info, trace, warn};
3
4use std::fmt::Debug;
5use std::io;
6use thiserror::Error as ThisError;
7
8use crate::StorageIdentifier;
9
10#[derive(ThisError, Debug)]
12#[allow(missing_docs)]
13pub enum Error {
14 #[error("Sorry. {0} is not implemented yet")]
15 Todo(&'static str),
16
17 #[error("General Xvc Remote Error: {source}")]
18 AnyhowError {
19 #[from]
20 source: anyhow::Error,
21 },
22
23 #[error("Xvc ECS Error: {source}")]
24 EcsError {
25 #[from]
26 source: xvc_core::XvcEcsError,
27 },
28
29 #[error("Xvc Core Error: {source}")]
30 CoreError {
31 #[from]
32 source: xvc_core::error::Error,
33 },
34
35 #[error("Xvc Config Error: {source}")]
36 ConfigError {
37 #[from]
38 source: xvc_core::XvcConfigError,
39 },
40
41 #[error("Walker Error: {source}")]
42 WalkerError {
43 #[from]
44 source: xvc_core::XvcWalkerError,
45 },
46 #[error("I/O Error: {source}")]
47 IoError {
48 #[from]
49 source: io::Error,
50 },
51 #[error("Crossbeam Send Error for Type: {t:?} {cause:?}")]
52 CrossbeamSendError { t: String, cause: String },
53
54 #[error("Uuid Error: {source:?}")]
55 UuidError {
56 #[from]
57 source: uuid::Error,
58 },
59
60 #[error("No Guid found for Xvc Repository")]
61 NoRepositoryGuidFound,
62
63 #[error("Cannot find storage with identifier: {identifier}")]
64 CannotFindStorageWithIdentifier { identifier: StorageIdentifier },
65
66 #[error("Cannot remove storage with identifier: {identifier}")]
67 CannotRemoveStorageWithIdentifier { identifier: StorageIdentifier },
68
69 #[error("Process Exec Error: {source}")]
70 ProcessExecError {
71 #[from]
72 source: subprocess::PopenError,
73 },
74
75 #[error("Process Error.\nSTDOUT:\n{stdout}\nSTDERR:\n{stderr}")]
76 ProcessError { stdout: String, stderr: String },
77
78 #[error("Cannot Find Executable: {source}")]
79 WhichError {
80 #[from]
81 source: which::Error,
82 },
83
84 #[error("Cloud credentials for storage '{storage_name}' not found. Please set ONE of the following pairs of environment variables: {var_pairs:?}")]
85 CloudCredentialsNotFound {
86 storage_name: String,
87 var_pairs: Vec<(String, String)>,
88 },
89
90 #[cfg(any(feature = "s3", feature = "minio"))]
91 #[error("Cloud Credentials Error: {source}")]
92 CloudCredentialsError {
93 #[from]
94 source: s3::creds::error::CredentialsError,
95 },
96 #[cfg(any(feature = "s3", feature = "minio"))]
97 #[error("S3 Error: {source}")]
98 S3Error {
99 #[from]
100 source: s3::error::S3Error,
101 },
102
103 #[error("Environment Variable Error: {source}")]
104 VarError {
105 #[from]
106 source: std::env::VarError,
107 },
108
109 #[error("This storage type does not support file sharing with signed URLs")]
110 StorageDoesNotSupportSignedUrls,
111}
112
113impl<T> From<crossbeam_channel::SendError<T>> for Error
114where
115 T: Debug,
116{
117 fn from(e: crossbeam_channel::SendError<T>) -> Self {
118 Error::CrossbeamSendError {
119 t: format!("{:#?}", e.0),
120 cause: e.to_string(),
121 }
122 }
123}
124
125impl Error {
126 pub fn debug(self) -> Self {
128 debug!("{}", self);
129 self
130 }
131 pub fn trace(self) -> Self {
133 trace!("{}", self);
134 self
135 }
136
137 pub fn warn(self) -> Self {
139 warn!("{}", self);
140 self
141 }
142 pub fn error(self) -> Self {
144 error!("{}", self);
145 self
146 }
147 pub fn info(self) -> Self {
149 info!("{}", self);
150 self
151 }
152 pub fn panic(self) -> Self {
154 panic!("{}", self);
155 }
156}
157
158pub type Result<T> = std::result::Result<T, Error>;