diff options
author | Till Hoeppner | 2015-07-24 00:02:16 +0200 |
---|---|---|
committer | Till Hoeppner | 2015-07-24 00:02:16 +0200 |
commit | 4ce03bf5f95c9b5099c890ac9de68596c5a3b1ff (patch) | |
tree | 841fa9938c4f8c0ae249ac3532a0ff245cc1acdb /src/lib.rs | |
parent | 47ebf402a67df74af0a25a3cac92012170029ad4 (diff) | |
download | ilc-4ce03bf5f95c9b5099c890ac9de68596c5a3b1ff.tar.gz ilc-4ce03bf5f95c9b5099c890ac9de68596c5a3b1ff.tar.xz ilc-4ce03bf5f95c9b5099c890ac9de68596c5a3b1ff.zip |
Half-decent error reporting
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -27,6 +27,8 @@ pub mod context; use std::convert::From; use std::{ io, result }; +use std::error::Error; +use std::fmt::{ self, Display, Formatter }; use chrono::format::ParseError; @@ -41,6 +43,31 @@ pub enum IlcError { Io(io::Error) } +impl Display for IlcError { + fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + fmt.write_str(self.description()) + } +} + +impl Error for IlcError { + fn description(&self) -> &str { + use IlcError::*; + match self { + &Parse(_) => "error while parsing", + &Chrono(_) => "error while parsing time strings", + &BincodeDecode => "error while decoding from binary", + &BincodeEncode => "error while encoding to binary", + &Io(_) => "error during input/output" + } + } + + fn cause(&self) -> Option<&Error> { + match self { + _ => None + } + } +} + impl From<ParseError> for IlcError { fn from(err: ParseError) -> IlcError { IlcError::Chrono(err) } } |