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
|
use std::convert::From;
use std::io;
use super::JoshutoErrorKind;
#[derive(Clone, Debug)]
pub struct JoshutoError {
_kind: JoshutoErrorKind,
_cause: String,
}
#[allow(dead_code)]
impl JoshutoError {
pub fn new(_kind: JoshutoErrorKind, _cause: String) -> Self {
Self { _kind, _cause }
}
pub fn kind(&self) -> &JoshutoErrorKind {
&self._kind
}
}
impl std::fmt::Display for JoshutoError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self._cause)
}
}
impl From<io::Error> for JoshutoError {
fn from(err: io::Error) -> Self {
Self {
_kind: JoshutoErrorKind::from(err.kind()),
_cause: err.to_string(),
}
}
}
impl From<globset::Error> for JoshutoError {
fn from(err: globset::Error) -> Self {
Self {
_kind: JoshutoErrorKind::from(err.kind()),
_cause: err.to_string(),
}
}
}
impl From<std::env::VarError> for JoshutoError {
fn from(err: std::env::VarError) -> Self {
Self {
_kind: JoshutoErrorKind::from(err),
_cause: "Environment variable not found".to_string(),
}
}
}
impl From<trash::Error> for JoshutoError {
fn from(err: trash::Error) -> Self {
let err = match err {
trash::Error::Unknown { description } => {
std::io::Error::new(std::io::ErrorKind::Other, description)
}
trash::Error::TargetedRoot => {
std::io::Error::new(std::io::ErrorKind::Other, "Targeted Root")
}
_ => std::io::Error::new(std::io::ErrorKind::Other, "Unknown Error"),
};
Self {
_kind: JoshutoErrorKind::from(err.kind()),
_cause: err.to_string(),
}
}
}
impl From<toml::de::Error> for JoshutoError {
fn from(err: toml::de::Error) -> Self {
Self {
_kind: JoshutoErrorKind::from(err),
_cause: "Failed to parse TOML".to_string(),
}
}
}
|