better error message for config issues
This commit is contained in:
parent
9c996b1029
commit
a791514cbe
@ -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)
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use redis::RedisError;
|
||||
use config::ConfigError;
|
||||
|
||||
pub type LJResult<T> = Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
#[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}")
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user