diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-05-07 20:04:13 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-05-07 20:04:13 -0400 |
commit | e67ea4c5f8e6d4790c43159e965417b59603e5a5 (patch) | |
tree | 293a9b8929ef103776953e2e188ad1681b48b91c /src/error | |
parent | c8709ff70570e9e8aa5f44c5e30c1027d9a0c701 (diff) |
add more automatic error handling
Diffstat (limited to 'src/error')
-rw-r--r-- | src/error/error_kind.rs | 6 | ||||
-rw-r--r-- | src/error/error_type.rs | 9 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/error/error_kind.rs b/src/error/error_kind.rs index b5aa835..679ad32 100644 --- a/src/error/error_kind.rs +++ b/src/error/error_kind.rs @@ -31,3 +31,9 @@ impl std::convert::From<&globset::ErrorKind> for JoshutoErrorKind { Self::Glob } } + +impl std::convert::From<std::env::VarError> for JoshutoErrorKind { + fn from(_: std::env::VarError) -> Self { + Self::EnvVarNotPresent + } +} diff --git a/src/error/error_type.rs b/src/error/error_type.rs index 80dc4bc..9ca849a 100644 --- a/src/error/error_type.rs +++ b/src/error/error_type.rs @@ -42,6 +42,15 @@ impl std::convert::From<globset::Error> for JoshutoError { } } +impl std::convert::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 std::convert::From<trash::Error> for JoshutoError { fn from(err: trash::Error) -> Self { let err = match err { |