diff options
author | Till Hoeppner | 2015-07-28 00:35:57 +0200 |
---|---|---|
committer | Till Hoeppner | 2015-07-28 00:35:57 +0200 |
commit | 01703f2dcd807f58c03a83bf1d3fa52e8023a0ad (patch) | |
tree | 8d6b48c48481ce6b824b517fd29182494e61a709 /src | |
parent | 2b5c034f133fe55aaf9e5d69c98cafcfee139a11 (diff) | |
download | ilc-01703f2dcd807f58c03a83bf1d3fa52e8023a0ad.tar.gz ilc-01703f2dcd807f58c03a83bf1d3fa52e8023a0ad.tar.xz ilc-01703f2dcd807f58c03a83bf1d3fa52e8023a0ad.zip |
Improved error reporting
Diffstat (limited to 'src')
-rw-r--r-- | src/format/msgpack.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 13 | ||||
-rw-r--r-- | src/main.rs | 2 |
3 files changed, 15 insertions, 4 deletions
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<Event<'a>>; fn next(&mut self) -> Option<::Result<Event<'a>>> { 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)) } } @@ -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 { |