aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-05-02 14:42:10 +0100
committerAkshay <[email protected]>2020-05-02 14:42:10 +0100
commit34b086d8f31e1c02e905f32a875a0e543bf34c23 (patch)
tree395942f7f794e9039049944b5c036b9dc2b1d766
parentf1f564dfcd328a1b36e6fefb37e023afebc9d68f (diff)
imple std::error::Error for FondantError
-rw-r--r--fondant_deps/src/lib.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/fondant_deps/src/lib.rs b/fondant_deps/src/lib.rs
index 82626b7..024207e 100644
--- a/fondant_deps/src/lib.rs
+++ b/fondant_deps/src/lib.rs
@@ -21,7 +21,9 @@ pub mod fondant_exports {
21} 21}
22 22
23use serde::{de::DeserializeOwned, Serialize}; 23use serde::{de::DeserializeOwned, Serialize};
24use std::path::{Path, PathBuf}; 24use std::error::Error;
25use std::fmt;
26use std::path::Path;
25 27
26#[derive(Debug)] 28#[derive(Debug)]
27/// Errors that `load` and `store` can result in 29/// Errors that `load` and `store` can result in
@@ -42,6 +44,32 @@ pub enum FondantError {
42 FileOpenError, 44 FileOpenError,
43} 45}
44 46
47impl fmt::Display for FondantError {
48 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49 let suggestion_text =
50 "HELP: You might have insufficient permissions to perform this action.";
51 match self {
52 FondantError::InvalidHomeDir => write!(f, "Failed to find home directory!"),
53 FondantError::ConfigParseError => write!(f, "Invalid configuration file!"),
54 FondantError::DirCreateErr(_) => {
55 write!(f, "Failed to write to configuration directory!")
56 }
57 FondantError::LoadError => write!(f, "Failed to load configuration file!"),
58 FondantError::FileWriteError => {
59 write!(f, "Failed to write configuration file! {}", suggestion_text)
60 }
61 FondantError::FileReadError => {
62 write!(f, "Failed to read configuration file! {}", suggestion_text)
63 }
64 FondantError::FileOpenError => {
65 write!(f, "Failed to open configuration file! {}", suggestion_text)
66 }
67 }
68 }
69}
70
71impl Error for FondantError {}
72
45/// Derive this trait on a struct to mark it as a 'configuration' struct. 73/// Derive this trait on a struct to mark it as a 'configuration' struct.
46pub trait Configure: Serialize + DeserializeOwned + Default { 74pub trait Configure: Serialize + DeserializeOwned + Default {
47 fn load_file<P: AsRef<Path>>(config_file: P) -> Result<Self, FondantError>; 75 fn load_file<P: AsRef<Path>>(config_file: P) -> Result<Self, FondantError>;