Fixed error handling

.eof() can return Err, so do not try to unwrap() it unconditionally.

Also, check result of .parse_whitespaces(), and report, if there is any
errors.

(thanks, @nixpulvis)
This commit is contained in:
Roma Sokolov 2016-02-05 10:26:59 +00:00
parent 34b3a1e9ce
commit 32f643f986

View File

@ -861,16 +861,16 @@ impl <T, Iter> Iterator for JSONStream<T, Iter>
// skip whitespaces, if any
// this helps with trailing whitespaces, since whitespaces between
// values are handled for us.
let _:Result<()> = self.deser.parse_whitespace();
// Since Deserializer.eof() always return Ok(_), it's safe to
// call .ok() here
if self.deser.eof().ok().unwrap() {
None
} else {
match de::Deserialize::deserialize(&mut self.deser) {
if let Err(e) = self.deser.parse_whitespace() {
return Some(Err(e))
};
match self.deser.eof() {
Ok(true) => None,
Ok(false) => match de::Deserialize::deserialize(&mut self.deser) {
Ok(v) => Some(Ok(v)),
Err(e) => Some(Err(e))
}
},
Err(e) => Some(Err(e))
}
}
}