diff options
| author | Gus Power <gus@infinitesidequests.com> | 2025-05-21 16:23:55 +0100 |
|---|---|---|
| committer | Gus Power <gus@infinitesidequests.com> | 2025-05-21 16:23:55 +0100 |
| commit | d7ce374a1741fdbb5c3aeef1218058a3d1060e88 (patch) | |
| tree | ac4297e69ce670155fcd3c37c29b085d3707decc /src/error.rs | |
| parent | 9ce9c101a10327b1eb6902133173119c3e0f3732 (diff) | |
config fallback w/ tests. introduced a macro to remove some test boilerplate around Result<T,E> and having return Ok(())
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) + } } } } |
