add: more ParseError variants
@@ -5,9 +5,11 @@ use std::fmt;
pub enum ParseError<'a> {
DuplicateField(Cow<'a, str>),
MissingArg,
+ MissingField(Cow<'a, str>),
InvalidNumber(Cow<'a, str>, Cow<'a, str>),
InvalidBoolean(Cow<'a, str>, Cow<'a, str>),
InvalidDuration(Cow<'a, str>, humantime::DurationError),
+ InvalidCid(Cow<'a, str>, cid::Error),
}
impl<'a> fmt::Display for ParseError<'a> {
@@ -16,11 +18,13 @@ impl<'a> fmt::Display for ParseError<'a> {
match *self {
DuplicateField(ref s) => write!(fmt, "field {:?} was duplicated", *s),
MissingArg => write!(fmt, "required field \"arg\" missing"),
+ MissingField(ref field) => write!(fmt, "required field {:?} missing", field),
InvalidNumber(ref k, ref v) => write!(fmt, "field {:?} invalid number: {:?}", *k, *v),
InvalidBoolean(ref k, ref v) => write!(fmt, "field {:?} invalid boolean: {:?}", *k, *v),
InvalidDuration(ref field, ref e) => {
- write!(fmt, "field {:?} invalid duration: {:?}", field, e)
+ write!(fmt, "field {:?} invalid duration: {}", field, e)
}
+ InvalidCid(ref field, ref e) => write!(fmt, "field {:?} invalid cid: {}", field, e),
}
}
}
@@ -30,6 +34,7 @@ impl<'a> std::error::Error for ParseError<'a> {
use ParseError::*;
match self {
InvalidDuration(_, e) => Some(e),
+ InvalidCid(_, e) => Some(e),
_ => None,
}
}
