config: Make panic messages more useful

This commit is contained in:
Kamal Marhubi 2016-02-01 18:40:32 -05:00
parent ee32615df1
commit 85d14617ce

View File

@ -218,12 +218,12 @@ macro_rules! create_config {
}
pub fn from_toml(toml: &str) -> Config {
let parsed = toml.parse().unwrap();
let parsed = toml.parse().expect("Could not parse TOML");
let parsed_config:ParsedConfig = match toml::decode(parsed) {
Some(decoded) => decoded,
None => {
println!("Decoding config file failed. Config:\n{}", toml);
let parsed: toml::Value = toml.parse().unwrap();
let parsed: toml::Value = toml.parse().expect("Could not parse TOML");
println!("\n\nParsed:\n{:?}", parsed);
panic!();
}
@ -235,10 +235,14 @@ macro_rules! create_config {
match key {
$(
stringify!($i) => {
self.$i = val.parse::<$ty>().unwrap();
self.$i = val.parse::<$ty>()
.expect(&format!("Failed to parse override for {} (\"{}\") as a {}",
stringify!($i),
val,
stringify!($ty)));
}
)+
_ => panic!("Bad config key!")
_ => panic!("Unknown config key in override: {}", key)
}
}