1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
use log::{debug, error, info, trace, warn};
use std::ffi::OsString;
use std::fmt::Debug;
use std::io;
use thiserror::Error as ThisError;
#[derive(ThisError, Debug)]
pub enum Error {
#[error("Sorry. {0} is not implemented yet")]
Todo(&'static str),
//
// #[error("Cannot find {xvc_path} in cache: {cache_path}")]
// CannotFindFileInCache {
// xvc_path: String,
// cache_path: String,
// },
// #[error("File not found: {path}")]
// FileNotFound { path: PathBuf },
// #[error("Internal Error: {message}")]
// InternalError { message: String },
// #[error("FS Extra error: {source}")]
// FileSystemExtraError {
// #[from]
// source: fs_extra::error::Error,
// },
// #[error("Jwalk Error: {source}")]
// JwalkError {
// #[from]
// source: jwalk::Error,
// },
// #[error("Conflicting Command Line Flags: {flags:?}")]
// ConflictingFlags { flags: &'static [String] },
// #[error("File System Walk Error: {error}")]
// FSWalkerError { error: String },
// #[error("Cannot infer format from file extension: {extension:?}")]
// CannotInferFormatFromExtension { extension: OsString },
// #[error("Format specification for input (stdin) required.")]
// FormatSpecificationRequired,
// #[error("Process Error - stdout: {stdout}\nstderr: {stderr}")]
// ProcessError { stdout: String, stderr: String },
// #[error("Process Exec Error: {source}")]
// ProcessExecError {
// #[from]
// source: subprocess::PopenError,
// },
// #[error("Cannot find XVC Root: {path}")]
// CannotFindXvcRoot { path: PathBuf },
//
// #[error("Thread Error")]
// ThreadError,
//
// #[error("Cannot nest XVC repositories: {path}")]
// CannotNestXvcRepositories { path: PathBuf },
//
// #[error("Cannot set step to both frozen and run_always")]
// CannotSetToBothFrozenAndRunAlways,
#[error("Regex Error: {source}")]
RegexError {
#[from]
source: regex::Error,
},
// #[error("Command Line Parsing Error: {source}")]
// ClapError {
// #[from]
// source: ClapError,
// },
// #[error("Invalid regular expression: {regex}")]
// InvalidRegexFormat { regex: String },
//
// #[error("Invalid lines definition: {line}")]
// InvalidLinesFormat { line: String },
//
// #[error("Step {step} not found in pipeline")]
// StepNotFoundInPipeline { step: String },
// #[error("System Time Error: {source}")]
// SystemTimeError {
// #[from]
// source: std::time::SystemTimeError,
// },
// #[error("[E1002] MsgPack Serialization Error: {source}")]
// MsgPackDecodeError {
// #[from]
// source: rmp_serde::decode::Error,
// },
// #[error("[E1003] MsgPack Serialization Error: {source}")]
// MsgPackEncodeError {
// #[from]
// source: rmp_serde::encode::Error,
// },
// #[error("[E1004] Json Serialization Error: {source}")]
// JsonError {
// #[from]
// source: serde_json::Error,
// },
// #[error("Encountered NULL value in JSON map")]
// JsonNullValueForKey { key: String },
//
#[error("TOML Serialization Error: {source}")]
TomlSerializationError {
#[from]
source: toml::ser::Error,
},
#[error("TOML Deserialization Error: {source}")]
TomlDeserializationError {
#[from]
source: toml::de::Error,
},
#[error("Yaml Error: {source}")]
YamlError {
#[from]
source: serde_yaml::Error,
},
#[error("Encountered NULL value in YAML map")]
YamlNullValueForKey { key: String },
// //// ****** Data Errors ******
// #[error("Unsupported Target Type: {path}")]
// UnsupportedTargetType { path: String },
// #[error("Target is ignored, please unignore in .xvcignore: {path}")]
// TargetIgnored { path: String },
//
// //// ****** Pipeline Errors ******
// #[error("[E2001] Step with name '{step_name}' already found in {pipeline_name}")]
// StepAlreadyFoundInPipeline {
// step_name: String,
// pipeline_name: String,
// },
// #[error("[E2002] Stage with name already found")]
// StepRequiresName,
// #[error("[E2003] The command xvc {command} requires subcommand.")]
// RequiresSubCommand { command: String },
// #[error("[E2004] Requires xvc repository.")]
// RequiresXvcRepository,
// #[error("Pipeline {name} already found")]
// PipelineAlreadyFound { name: String },
// #[error("Pipeline {name} is not found")]
// NoPipelinesFound { name: String },
// #[error("Pipeline Steps Contain Cycle")]
// PipelineStepsContainCycle { pipeline: String, step: String },
// #[error("Cannot delete last pipeline")]
// CannotDeleteLastPipeline,
// #[error("Cannot delete default pipeline: {name}")]
// CannotDeleteDefaultPipeline { name: String },
//
// #[error("Pipeline cannot depend to itself")]
// PipelineCannotDependToItself,
//
// #[error("Step cannot depend to itself")]
// StepCannotDependToItself,
//
// #[error("Internal Error: Content Digest for Pipeline Dependencies is not available. ")]
// NoContentDigestForPipelines,
//
// #[error("Internal Error: Content Digest for Step Dependencies is not available. ")]
// NoContentDigestForSteps,
//
#[error("I/O Error: {source}")]
IoError {
#[from]
source: io::Error,
},
#[error("Cannot convert enum type from string: {cause_key}")]
EnumTypeConversionError { cause_key: String },
// #[error("Unicode/UTF-8 Error: {cause:?}")]
// UnicodeError { cause: OsString },
//
// #[error("Path must be file, not symlink or directory")]
// RequiresAFile { path: PathBuf },
//
// #[error("Path is not in XVC Repository: {path:?}")]
// PathNotInXvcRepository { path: OsString },
//
// #[error("Path not found in Path Metadata Map: {path:?}")]
// PathNotFoundInPathMetadataMap { path: OsString },
//
// #[error("Path has no parent: {path:?}")]
// PathHasNoParent { path: OsString },
//
// #[error("Path has no filename: {path:?}")]
// PathHasNoFilename { path: OsString },
//
// #[error("Path has no modification time: {path:?}")]
// PathHasNoModificationTime { path: OsString },
//
// #[error("Cannot Parse Integer: {source:?}")]
// CannotParseInteger {
// #[from]
// source: ParseIntError,
// },
//
#[error("Config source for level {config_source:?} not found at {path:?}")]
ConfigurationForSourceNotFound {
config_source: String,
path: OsString,
},
#[error("Config value type mismatch: {key} ")]
MismatchedValueType { key: String },
#[error("Config key not found: {key}")]
ConfigKeyNotFound { key: String },
//
#[error("Cannot Determine System Configuration Path")]
CannotDetermineSystemConfigurationPath,
#[error("Cannot Determine User Configuration Path")]
CannotDetermineUserConfigurationPath,
// #[error("No .xvcignore patterns found. There may be a problem in your setup")]
// RequiresXvcIgnore,
//
// // #[error("XvcIgnore Error: {source}")]
// // XvcIgnoreError {
// // #[from]
// // source: ignore::Error,
// // },
// #[error("Internal Error: XvcDependencyComparisonError in Pipelines")]
// XvcDependencyComparisonError,
//
// #[error("Glob Error: {source}")]
// GlobError {
// #[from]
// source: glob::GlobError,
// },
//
// #[error("Glob Pattern Error: {source}")]
// GlobPatternError {
// #[from]
// source: glob::PatternError,
// },
//
#[error("Enum Parsing Error")]
StrumError {
#[from]
source: strum::ParseError,
},
//
// #[error("Missing key: {key}")]
// RequiresKey { key: String },
//
// #[error("Missing value for key: {key}")]
// KeyNotFound { key: String },
//
// #[error("Missing value for key: {key} in {path}")]
// KeyNotFoundInDocument { key: String, path: PathBuf },
//
// #[error("Parameter file not found: {path}")]
// ParamFileNotFound { path: PathBuf },
//
// #[error("Invalid Parameter Format: {param} ")]
// InvalidParameterFormat { param: String },
//
// #[error("Unsupported param file format: {path:?} ")]
// UnsupportedParamFileFormat { path: OsString },
//
// #[error("Path strip prefix error: {source}")]
// StringPrefixError {
// #[from]
// source: std::path::StripPrefixError,
// },
//
// #[error("Crossbeam Send Error for Type: {t:?} {cause:?}")]
// CrossbeamSendError { t: String, cause: String },
//
// #[error("Only files or directories can be added: {path:?} ")]
// OnlyFilesAndDirectoriesCanBeAdded { path: OsString },
//
// #[error("This directory already belongs to an XVC repository {path:?}")]
// DirectoryContainsXVCAlready { path: OsString },
//
// #[error("This directory is not in a Git Repository {path:?}")]
// PathNotInGitRepository { path: OsString },
//
// #[error("Cannot find a related entity: {entity}")]
// NoParentEntityFound { entity: usize },
//
// #[error("More than one root entity found in an 1-N relation")]
// MoreThanOneParentFound { entity: usize },
//
// #[error("Cannot find key in store: {key}")]
// CannotFindKeyInStore { key: usize },
//
// #[error("Cannot find xvc meta file in {path:?}")]
// CannotFindXvcMetaFile { path: OsString },
//
// #[error("Cannot find Pipeline: {name}")]
// CannotFindPipeline { name: String },
//
// #[error("Cannot find Step: {name}")]
// CannotFindStep { name: String },
//
// #[error("Internal Store Conversion Error")]
// StoreConversionError,
//
// #[error("Can initialize {object} only once")]
// CanInitializeOnlyOnce { object: String },
//
// #[error("Relative Path Conversion Error: {source}")]
// RelativePathError {
// #[from]
// source: relative_path::FromPathError,
// },
//
// #[error("Error in Key/Value Store: {source}")]
// SledError {
// #[from]
// source: SledError,
// },
// // #[error("the data for key `{0}` is not available")]
// // Redaction(String),
// // #[error("invalid header (expected {expected:?}, found {found:?})")]
// // InvalidHeader { expected: String, found: String },
// // #[error("unknown data store error")]
// // Unknown
// #[error("ScanDir Error: {source}")]
// ScanDirError {
// #[from]
// source: ScanDirError,
// },
// #[error("ScanDir Error: {sources:?}")]
// ScanDirErrors { sources: Vec<ScanDirError> },
}
// impl<T> From<crossbeam_channel::SendError<T>> for Error
// where
// T: Debug,
// {
// fn from(e: crossbeam_channel::SendError<T>) -> Self {
// Error::CrossbeamSendError {
// t: format!("{:#?}", e.0),
// cause: e.to_string(),
// }
// }
// }
//
impl Error {
pub fn debug(self) -> Self {
debug!("{}", self);
self
}
pub fn trace(self) -> Self {
trace!("{}", self);
self
}
pub fn warn(self) -> Self {
warn!("{}", self);
self
}
pub fn error(self) -> Self {
error!("{}", self);
self
}
pub fn info(self) -> Self {
info!("{}", self);
self
}
pub fn panic(self) -> Self {
panic!("{}", self);
}
}
pub type Result<T> = std::result::Result<T, Error>;