From a791514cbe2aacea80da1c305f7747edd5a713f3 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Thu, 8 Jun 2023 20:34:09 +0200 Subject: [PATCH] better error message for config issues --- src/conf.rs | 4 ++-- src/errors.rs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/conf.rs b/src/conf.rs index 02a4c15..fe5e762 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -1,6 +1,6 @@ use config::Config; use serde::{Serialize,Deserialize}; -use crate::errors::LJResult; +use crate::errors::{LJError,LJResult}; use crate::transformer; #[derive(Serialize, Deserialize, Debug, Clone)] @@ -46,7 +46,7 @@ impl Conf { .add_source(config::File::with_name(path)) .build()?; - let conf : Conf = settings.try_deserialize()?; + let conf : Conf = settings.try_deserialize().map_err(LJError::Config)?; Ok(conf) } diff --git a/src/errors.rs b/src/errors.rs index 45363e5..ff40f33 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,11 +1,13 @@ use std::error::Error; use std::fmt; use redis::RedisError; +use config::ConfigError; pub type LJResult = Result>; #[derive(Debug)] pub enum LJError { + Config(ConfigError), RedisConnect(RedisError), HeliosDeviceMissing } @@ -15,6 +17,10 @@ impl fmt::Display for LJError { use LJError::*; match self { + Config(err) => { + write!(f, "unable to load config file: {err}") + }, + RedisConnect(err) => { write!(f, "unable to connect to redis server: {err}") },