From f0648bcc4e7a6b7ce3f59013f25413a667dc507a Mon Sep 17 00:00:00 2001 From: Julian T Date: Tue, 27 Jul 2021 17:46:28 +0200 Subject: Sort by timestamps and switch to thiserror crate --- src/context.rs | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) (limited to 'src/context.rs') diff --git a/src/context.rs b/src/context.rs index f7b97ed..660c201 100644 --- a/src/context.rs +++ b/src/context.rs @@ -27,12 +27,28 @@ pub struct Options { pub url_prefix: Option, } -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] pub enum ConfigError { - Reading(io::Error), - Parsing(serde_yaml::Error), - CompilePattern(glob::PatternError), - CompileTemplate(tera::Error), + #[error("reading from file")] + Reading { + #[from] + source: io::Error, + }, + #[error("parsing config file")] + Parsing { + #[from] + source: serde_yaml::Error, + }, + #[error("compiling glob pattern")] + CompilePattern { + #[from] + source: glob::PatternError, + }, + #[error("compiling templates")] + CompileTemplate { + #[from] + source: tera::Error, + }, } #[derive(Deserialize, Debug, Serialize)] @@ -148,27 +164,3 @@ impl Config { } - -impl From for ConfigError { - fn from(error: io::Error) -> Self { - ConfigError::Reading(error) - } -} - -impl From for ConfigError { - fn from(error: serde_yaml::Error) -> Self { - ConfigError::Parsing(error) - } -} - -impl From for ConfigError { - fn from(error: glob::PatternError) -> Self { - ConfigError::CompilePattern(error) - } -} - -impl From for ConfigError { - fn from(error: tera::Error) -> Self { - ConfigError::CompileTemplate(error) - } -} -- cgit v1.2.3