summaryrefslogtreecommitdiff
path: root/Lib/json
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-01-03 08:44:15 +0200
committerEzio Melotti <ezio.melotti@gmail.com>2013-01-03 08:44:15 +0200
commit37623ab5f12b9034b1935f9507c3a5d1786dfd9e (patch)
tree729a3010f82d3017a0220edc08cfdaf13d44503e /Lib/json
parentfd53a5a01150de79cfb1673e89711c6cd6258ea2 (diff)
downloadcpython-git-37623ab5f12b9034b1935f9507c3a5d1786dfd9e.tar.gz
#16009: JSON error messages now provide more information. Patch by Serhiy Storchaka.
Diffstat (limited to 'Lib/json')
-rw-r--r--Lib/json/decoder.py14
-rw-r--r--Lib/json/scanner.py4
2 files changed, 9 insertions, 9 deletions
diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py
index 9b7438cd5b..7e5a099b5f 100644
--- a/Lib/json/decoder.py
+++ b/Lib/json/decoder.py
@@ -188,8 +188,8 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
try:
value, end = scan_once(s, end)
- except StopIteration:
- raise ValueError(errmsg("Expecting object", s, end))
+ except StopIteration as err:
+ raise ValueError(errmsg("Expecting value", s, err.value)) from None
pairs_append((key, value))
try:
nextchar = s[end]
@@ -232,8 +232,8 @@ def JSONArray(s_and_end, scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
while True:
try:
value, end = scan_once(s, end)
- except StopIteration:
- raise ValueError(errmsg("Expecting object", s, end))
+ except StopIteration as err:
+ raise ValueError(errmsg("Expecting value", s, err.value)) from None
_append(value)
nextchar = s[end:end + 1]
if nextchar in _ws:
@@ -243,7 +243,7 @@ def JSONArray(s_and_end, scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
if nextchar == ']':
break
elif nextchar != ',':
- raise ValueError(errmsg("Expecting ',' delimiter", s, end))
+ raise ValueError(errmsg("Expecting ',' delimiter", s, end - 1))
try:
if s[end] in _ws:
end += 1
@@ -358,6 +358,6 @@ class JSONDecoder(object):
"""
try:
obj, end = self.scan_once(s, idx)
- except StopIteration:
- raise ValueError("No JSON object could be decoded")
+ except StopIteration as err:
+ raise ValueError(errmsg("Expecting value", s, err.value)) from None
return obj, end
diff --git a/Lib/json/scanner.py b/Lib/json/scanner.py
index 23eef61b94..86426cde1a 100644
--- a/Lib/json/scanner.py
+++ b/Lib/json/scanner.py
@@ -29,7 +29,7 @@ def py_make_scanner(context):
try:
nextchar = string[idx]
except IndexError:
- raise StopIteration
+ raise StopIteration(idx)
if nextchar == '"':
return parse_string(string, idx + 1, strict)
@@ -60,7 +60,7 @@ def py_make_scanner(context):
elif nextchar == '-' and string[idx:idx + 9] == '-Infinity':
return parse_constant('-Infinity'), idx + 9
else:
- raise StopIteration
+ raise StopIteration(idx)
def scan_once(string, idx):
try: