Merge pull request #797 from kamalmarhubi/config-expect

config: Make panic messages more useful
This commit is contained in:
Marcus Klaas de Vries
2016-02-03 06:08:34 +01:00
+8 -4
View File
@@ -218,12 +218,12 @@ fn fill_from_parsed_config(mut self, parsed: ParsedConfig) -> 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 @@ pub fn override_value(&mut self, key: &str, val: &str) {
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)
}
}