Update the location of json errors coming from "Deserialize"

This commit is contained in:
Erick Tryzelaar 2015-03-30 19:50:41 -07:00
parent 3167da72d8
commit bfe7a04c4d
2 changed files with 14 additions and 8 deletions

View File

@ -97,7 +97,7 @@ impl<Iter> Deserializer<Iter>
return Err(self.error(ErrorCode::EOFWhileParsingValue)); return Err(self.error(ErrorCode::EOFWhileParsingValue));
} }
match self.ch_or_null() { let value = match self.ch_or_null() {
b'n' => { b'n' => {
try!(self.parse_ident(b"ull")); try!(self.parse_ident(b"ull"));
visitor.visit_unit() visitor.visit_unit()
@ -127,6 +127,12 @@ impl<Iter> Deserializer<Iter>
_ => { _ => {
Err(self.error(ErrorCode::ExpectedSomeValue)) Err(self.error(ErrorCode::ExpectedSomeValue))
} }
};
match value {
Ok(value) => Ok(value),
Err(Error::SyntaxError(code, _, _)) => Err(self.error(code)),
Err(err) => Err(err),
} }
} }

View File

@ -861,9 +861,9 @@ fn test_parse_object() {
#[test] #[test]
fn test_parse_struct() { fn test_parse_struct() {
test_parse_err::<Outer>(vec![ test_parse_err::<Outer>(vec![
("5", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), ("5", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 2)),
("\"hello\"", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), ("\"hello\"", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 8)),
("{\"inner\": true}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), ("{\"inner\": true}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 15)),
]); ]);
test_parse_ok(vec![ test_parse_ok(vec![
@ -924,10 +924,10 @@ fn test_parse_enum_errors() {
("{}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 2)), ("{}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 2)),
("{\"Dog\":", Error::SyntaxError(ErrorCode::EOFWhileParsingValue, 1, 8)), ("{\"Dog\":", Error::SyntaxError(ErrorCode::EOFWhileParsingValue, 1, 8)),
("{\"Dog\":}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 8)), ("{\"Dog\":}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 8)),
("{\"unknown\":[]}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), ("{\"unknown\":[]}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 11)),
("{\"Dog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), ("{\"Dog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 9)),
("{\"Frog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), ("{\"Frog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 10)),
("{\"Cat\":[]}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), ("{\"Cat\":[]}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 9)),
]); ]);
} }