Skip to content

Commit 33dd3fe

Browse files
author
Bogdan Marinescu
committed
More verrbose errors for JSON parsing
This commit adds information about the location of problematic JSON files when reporting a JSON parsing error. Before this commit: ``` [ERROR] Expecting property name: line 7 column 9 (char 188) ``` After this commit: ``` Error parsing 'core/mbed_lib.json': [ERROR] Expecting property name: line 7 column 9 (char 188) ```
1 parent 6f86064 commit 33dd3fe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,12 @@ def dict_to_ascii(input):
196196
# Read a JSON file and return its Python representation, transforming all the strings from Unicode
197197
# to ASCII. The order of keys in the JSON file is preserved.
198198
def json_file_to_dict(fname):
199-
with open(fname, "rt") as f:
200-
return dict_to_ascii(json.load(f, object_pairs_hook=OrderedDict))
199+
try:
200+
with open(fname, "rt") as f:
201+
return dict_to_ascii(json.load(f, object_pairs_hook=OrderedDict))
202+
except (ValueError, IOError):
203+
sys.stderr.write("Error parsing '%s':\n" % fname)
204+
raise
201205

202206
# Wowza, double closure
203207
def argparse_type(casedness, prefer_hyphen=False) :

0 commit comments

Comments
 (0)