From bfe7a04c4d1e8a4d70a84b64484295fca42ac732 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 30 Mar 2015 19:50:41 -0700 Subject: [PATCH] Update the location of json errors coming from "Deserialize" --- src/json/de.rs | 8 +++++++- tests/test_json.rs | 14 +++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/json/de.rs b/src/json/de.rs index 8cce4bdc..ef89807b 100644 --- a/src/json/de.rs +++ b/src/json/de.rs @@ -97,7 +97,7 @@ impl Deserializer return Err(self.error(ErrorCode::EOFWhileParsingValue)); } - match self.ch_or_null() { + let value = match self.ch_or_null() { b'n' => { try!(self.parse_ident(b"ull")); visitor.visit_unit() @@ -127,6 +127,12 @@ impl Deserializer _ => { Err(self.error(ErrorCode::ExpectedSomeValue)) } + }; + + match value { + Ok(value) => Ok(value), + Err(Error::SyntaxError(code, _, _)) => Err(self.error(code)), + Err(err) => Err(err), } } diff --git a/tests/test_json.rs b/tests/test_json.rs index c92f5995..ad843058 100644 --- a/tests/test_json.rs +++ b/tests/test_json.rs @@ -861,9 +861,9 @@ fn test_parse_object() { #[test] fn test_parse_struct() { test_parse_err::(vec![ - ("5", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), - ("\"hello\"", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), - ("{\"inner\": true}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), + ("5", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 2)), + ("\"hello\"", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 8)), + ("{\"inner\": true}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 15)), ]); test_parse_ok(vec![ @@ -924,10 +924,10 @@ fn test_parse_enum_errors() { ("{}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 2)), ("{\"Dog\":", Error::SyntaxError(ErrorCode::EOFWhileParsingValue, 1, 8)), ("{\"Dog\":}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 8)), - ("{\"unknown\":[]}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), - ("{\"Dog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), - ("{\"Frog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), - ("{\"Cat\":[]}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 0, 0)), + ("{\"unknown\":[]}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 11)), + ("{\"Dog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 9)), + ("{\"Frog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 10)), + ("{\"Cat\":[]}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 9)), ]); }