Skip to content

Commit e9d225b

Browse files
authored
Merge pull request #2151 from mbedmicro/verbose_json_errors
More verrbose errors for JSON parsing
2 parents 99dbc8b + 33dd3fe commit e9d225b

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)