From 34b086d8f31e1c02e905f32a875a0e543bf34c23 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 2 May 2020 19:12:10 +0530 Subject: imple std::error::Error for FondantError --- fondant_deps/src/lib.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'fondant_deps/src') 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 { } use serde::{de::DeserializeOwned, Serialize}; -use std::path::{Path, PathBuf}; +use std::error::Error; +use std::fmt; +use std::path::Path; #[derive(Debug)] /// Errors that `load` and `store` can result in @@ -42,6 +44,32 @@ pub enum FondantError { FileOpenError, } +impl fmt::Display for FondantError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let suggestion_text = + "HELP: You might have insufficient permissions to perform this action."; + match self { + FondantError::InvalidHomeDir => write!(f, "Failed to find home directory!"), + FondantError::ConfigParseError => write!(f, "Invalid configuration file!"), + FondantError::DirCreateErr(_) => { + write!(f, "Failed to write to configuration directory!") + } + FondantError::LoadError => write!(f, "Failed to load configuration file!"), + FondantError::FileWriteError => { + write!(f, "Failed to write configuration file! {}", suggestion_text) + } + FondantError::FileReadError => { + write!(f, "Failed to read configuration file! {}", suggestion_text) + } + FondantError::FileOpenError => { + write!(f, "Failed to open configuration file! {}", suggestion_text) + } + } + } +} + +impl Error for FondantError {} + /// Derive this trait on a struct to mark it as a 'configuration' struct. pub trait Configure: Serialize + DeserializeOwned + Default { fn load_file>(config_file: P) -> Result; -- cgit v1.2.3