diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-09-11 13:26:11 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-09-11 13:26:11 -0400 |
commit | 362cf4556aebc365d39d41b82f6c815385ad3637 (patch) | |
tree | 4eba9e62aee11efcc27d82b2f9e82d7aa9117023 /src/error | |
parent | 513404430257a2b7b381931d540b1fbf44284560 (diff) |
add more helpful error messages
Diffstat (limited to 'src/error')
-rw-r--r-- | src/error/error_kind.rs | 1 | ||||
-rw-r--r-- | src/error/error_type.rs | 26 |
2 files changed, 12 insertions, 15 deletions
diff --git a/src/error/error_kind.rs b/src/error/error_kind.rs index 50fbf16..a03cd13 100644 --- a/src/error/error_kind.rs +++ b/src/error/error_kind.rs @@ -13,6 +13,7 @@ pub enum JoshutoErrorKind { ParseError, ClipboardError, TomlDeError(toml::de::Error), + TrashError, Glob, diff --git a/src/error/error_type.rs b/src/error/error_type.rs index ef147b8..31ffa23 100644 --- a/src/error/error_type.rs +++ b/src/error/error_type.rs @@ -28,54 +28,50 @@ impl std::fmt::Display for JoshutoError { impl From<io::Error> for JoshutoError { fn from(err: io::Error) -> Self { + let cause = err.to_string(); Self { _kind: JoshutoErrorKind::from(err.kind()), - _cause: err.to_string(), + _cause: cause, } } } impl From<globset::Error> for JoshutoError { fn from(err: globset::Error) -> Self { + let cause = err.to_string(); Self { _kind: JoshutoErrorKind::from(err.kind()), - _cause: err.to_string(), + _cause: cause, } } } impl From<std::env::VarError> for JoshutoError { fn from(err: std::env::VarError) -> Self { + let cause = err.to_string(); Self { _kind: JoshutoErrorKind::from(err), - _cause: "Environment variable not found".to_string(), + _cause: cause, } } } 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"), - }; + let cause = err.to_string(); Self { - _kind: JoshutoErrorKind::from(err.kind()), - _cause: err.to_string(), + _kind: JoshutoErrorKind::TrashError, + _cause: cause, } } } impl From<toml::de::Error> for JoshutoError { fn from(err: toml::de::Error) -> Self { + let cause = err.to_string(); Self { _kind: JoshutoErrorKind::from(err), - _cause: "Failed to parse TOML".to_string(), + _cause: cause, } } } |