[snowpatch] [PATCH] settings: print better errors when config deserialisation fails

Andrew Donnellan andrew.donnellan at au1.ibm.com
Thu Apr 14 17:08:15 AEST 2016


When decoding the config fails, panic with the full decode error so the
user has some idea where their configuration is wrong.

Closes: #23 ("Better error messages when config deserialisation fails")
Signed-off-by: Andrew Donnellan <andrew.donnellan at au1.ibm.com>
---
 src/settings.rs | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/settings.rs b/src/settings.rs
index 13c4c51..77e5e11 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -15,10 +15,12 @@
 //
 
 use toml;
-use toml::{Parser, Value};
+use toml::{Parser, Value, Decoder};
 
 use git2::{Repository, Error};
 
+use rustc_serialize::Decodable;
+
 use std::fs::File;
 use std::io::Read;
 use std::collections::BTreeMap;
@@ -92,8 +94,8 @@ pub fn parse(path: String) -> Config {
 
     let config = Value::Table(toml.unwrap());
 
-    match toml::decode(config) {
-        Some(t) => t,
-        None => panic!("Couldn't deserialize config, exiting.")
+    match Config::decode::<toml::Decoder>(&mut toml::Decoder::new(config)) {
+        Ok(t) => t,
+        Err(err) => panic!(format!("Couldn't deserialise config: {:?}", err))
     }
 }
-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan at au1.ibm.com  IBM Australia Limited



More information about the snowpatch mailing list