weldscli_lib/errors/
mod.rs1use std::path::PathBuf;
2pub type Result<T> = std::result::Result<T, WeldsError>;
3use welds::errors::WeldsError as WeldsCoreError;
4
5#[derive(Debug)]
6pub enum WeldsError {
7 MissingSchemaFile(PathBuf),
8 ReadError(PathBuf),
9 InvalidProject,
10 IoError(std::io::Error),
11 ConfigReadError(PathBuf),
12 ConfigWrite,
13 Core(WeldsCoreError),
14}
15
16impl std::error::Error for WeldsError {}
17
18impl std::fmt::Display for WeldsError {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 use WeldsError::*;
21
22 match self {
23 MissingSchemaFile(path) => {
24 write!(
25 f,
26 "The schema definition file {} could not be found.",
27 path.to_string_lossy()
28 )
29 }
30 ReadError(path) => write!(
31 f,
32 "There was an error reading the file {}",
33 path.to_string_lossy()
34 ),
35 ConfigReadError(path) => write!(
36 f,
37 "There is an error in the config file {}. ",
38 path.to_string_lossy()
39 ),
40 IoError(inner) => write!(f, "There was an IO error: {}", inner),
41 InvalidProject => write!(
42 f,
43 "It doesn't appear you are working in a valid rust project."
44 ),
45 ConfigWrite => write!(f, "There was an unknown error writing the weld.yaml config"),
46 Core(inner) => write!(f, "{}", inner),
47 }
48 }
49}
50
51impl From<std::io::Error> for WeldsError {
52 fn from(inner: std::io::Error) -> WeldsError {
53 WeldsError::IoError(inner)
54 }
55}
56
57impl From<WeldsCoreError> for WeldsError {
58 fn from(inner: WeldsCoreError) -> WeldsError {
59 WeldsError::Core(inner)
60 }
61}