diff options
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/error.rs b/src/error.rs index 3e05d2a..429aa58 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,3 +1,4 @@ +use homedir::GetHomeError; use reqwest::{Error as ReqwestError, Url}; use serde_json::Error as JsonError; use std::fmt; @@ -7,17 +8,24 @@ use std::path::PathBuf; pub type AppResult<T> = Result<T, AppError>; #[derive(Debug)] pub enum AppError { - FileNotFound(PathBuf), - IoError(io::Error), + ConfigFileNotFound(PathBuf), + ConfigFileNotProvided, ConfigParseError { source: JsonError, path: PathBuf }, + IoError(io::Error), RequestFailed { url: Url, source: ReqwestError }, InvalidResponse { url: Url, reason: String }, + UnableToGetHomeDirectory(GetHomeError), } impl fmt::Display for AppError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::FileNotFound(path) => write!(f, "File not found: {}", path.display()), + Self::ConfigFileNotFound(path) => { + write!(f, "Config file not found: {}", path.display()) + } + Self::ConfigFileNotProvided => { + write!(f, "Config file not provided") + } Self::IoError(err) => write!(f, "I/O error: {}", err), Self::ConfigParseError { path, .. } => { write!(f, "Failed to parse config at {}", path.display()) @@ -26,6 +34,9 @@ impl fmt::Display for AppError { Self::InvalidResponse { url, reason } => { write!(f, "Invalid response from {}: {}", url, reason) } + Self::UnableToGetHomeDirectory(err) => { + write!(f, "Failed to get home directory: {}", err) + } } } } |
