From 01703f2dcd807f58c03a83bf1d3fa52e8023a0ad Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Tue, 28 Jul 2015 00:35:57 +0200 Subject: Improved error reporting --- src/format/msgpack.rs | 4 ++-- src/lib.rs | 13 ++++++++++++- src/main.rs | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/format/msgpack.rs b/src/format/msgpack.rs index 3519b76..d823a6d 100644 --- a/src/format/msgpack.rs +++ b/src/format/msgpack.rs @@ -34,14 +34,14 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { type Item = ::Result>; fn next(&mut self) -> Option<::Result>> { Some(Decodable::decode(&mut Decoder::new(&mut self.input)) - .map_err(|_| ::IlcError::BincodeDecode)) + .map_err(|e| ::IlcError::MsgpackDecode(e))) } } impl<'a, W> Encode<'a, W> for Msgpack where W: Write { fn encode(&'a self, _context: &'a Context, mut output: W, event: &'a Event) -> ::Result<()> { event.encode(&mut Encoder::new(&mut output)) - .map_err(|_| ::IlcError::BincodeEncode) + .map_err(|e| ::IlcError::MsgpackEncode(e)) } } diff --git a/src/lib.rs b/src/lib.rs index c817e6c..422ca07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,6 +41,8 @@ pub enum IlcError { Chrono(ParseError), BincodeDecode, BincodeEncode, + MsgpackEncode(msgpack::encode::serialize::Error), + MsgpackDecode(msgpack::decode::serialize::Error), Io(io::Error) } @@ -58,13 +60,22 @@ impl Error for IlcError { &Chrono(_) => "error while parsing time strings", &BincodeDecode => "error while decoding from binary", &BincodeEncode => "error while encoding to binary", + &MsgpackDecode(_) => "error while decoding from msgpack", + &MsgpackEncode(_) => "error while encoding to msgpack", &Io(_) => "error during input/output" } } fn cause(&self) -> Option<&Error> { + use IlcError::*; match self { - _ => None + &Parse(ref _e) => None, + &Chrono(ref e) => Some(e), + &BincodeDecode => None, + &BincodeEncode => None, + &MsgpackDecode(ref e) => Some(e), + &MsgpackEncode(ref e) => Some(e), + &Io(ref e) => Some(e) } } } diff --git a/src/main.rs b/src/main.rs index 81cfbd9..aa39b69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -208,7 +208,7 @@ fn main() { for e in decoder.decode_box(&context, &mut input) { let m = match e { Ok(m) => m, - Err(err) => panic!(err) + Err(err) => error(Box::new(err)) }; match m { -- cgit v1.2.3