Skip to content

Commit

Permalink
Create new error kind for invalid boolean values.
Browse files Browse the repository at this point in the history
  • Loading branch information
William Bartlett committed Jan 22, 2019
1 parent f282060 commit e39a9b8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<'de, 'a, R: Read> de::Deserializer<'de> for &'a mut Deserializer<R> {
match s.as_str() {
"true" | "1" => visitor.visit_bool(true),
"false" | "0" => visitor.visit_bool(false),
_ => Err(ErrorKind::UnexpectedToken(
_ => Err(ErrorKind::InvalidValue(
"boolean [true,false,1,0]".into(),
format!("{}", s)
).into()),
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ error_chain! {
description("unexpected token")
display("Expected token {}, found {}", token, found)
}
InvalidValue(expected: String, found: String) {
description("invalid value")
display("Expected value {}, found {}", expected, found)
}
Custom(field: String) {
description("other error")
display("custom: '{}'", field)
Expand Down

0 comments on commit e39a9b8

Please sign in to comment.