feat(settings): log path to field where config deserialization failed (#78)

Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
Sanchith Hegde
2022-12-07 14:32:12 +05:30
committed by GitHub
parent 18aed187aa
commit b72e0df512
4 changed files with 16 additions and 5 deletions

10
Cargo.lock generated
View File

@ -2650,6 +2650,7 @@ dependencies = [
"router_env",
"serde",
"serde_json",
"serde_path_to_error",
"serde_qs",
"serde_urlencoded",
"sha2",
@ -2894,6 +2895,15 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_path_to_error"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "184c643044780f7ceb59104cef98a5a6f12cb2288a7bc701ab93a362b49fd47d"
dependencies = [
"serde",
]
[[package]]
name = "serde_qs"
version = "0.10.1"

View File

@ -53,6 +53,7 @@ reqwest = { version = "0.11.12", features = ["json"] }
ring = "0.16.20"
serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0.85"
serde_path_to_error = "0.1.8"
serde_qs = { version = "0.10.1", optional = true }
serde_urlencoded = "0.7.1"
sha2 = "0.10.5"

View File

@ -165,10 +165,10 @@ impl Settings {
)
.build()?;
config.try_deserialize().map_err(|e| {
logger::error!("Unable to source config file");
eprintln!("Unable to source config file");
BachError::from(e)
serde_path_to_error::deserialize(config).map_err(|error| {
logger::error!(%error, "Unable to deserialize application configuration");
eprintln!("Unable to deserialize application configuration: {error}");
BachError::from(error.into_inner())
})
}
}

View File

@ -119,7 +119,7 @@ pub enum BachError {
#[error("{{ error_description: Error while parsing, error_message: {0} }}")]
EParsingError(error_stack::Report<ParsingError>),
#[error("Environment configuration error: {0}")]
#[error("Application configuration error: {0}")]
ConfigurationError(ConfigError),
#[error("{{ error_description: Database operation failed, error_message: {0} }}")]