Skip to content

Commit f1d3d09

Browse files
authored
Merge pull request #342 from dartmouth-pbs/bf-do-not-blow-on-strange-json
ENH: do not blow hard if prettyfication of json fails - just store as json module stores it
2 parents 3e02eca + ca47f8b commit f1d3d09

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

heudiconv/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,17 @@ def treat_infofile(filename):
251251
j = json.load(f)
252252

253253
j_slim = slim_down_info(j)
254-
j_pretty = json_dumps_pretty(j_slim, indent=2, sort_keys=True)
254+
dumps_kw = dict(indent=2, sort_keys=True)
255+
try:
256+
j_pretty = json_dumps_pretty(j_slim, **dumps_kw)
257+
except AssertionError as exc:
258+
lgr.warning(
259+
"Prettyfication of .json failed (%s). "
260+
"Original .json will be kept as is. Please share (if you could) "
261+
"that file (%s) with HeuDiConv developers"
262+
% (str(exc), filename)
263+
)
264+
j_pretty = json.dumps(j_slim, **dumps_kw)
255265

256266
set_readonly(filename, False)
257267
with open(filename, 'wt') as fp:

0 commit comments

Comments
 (0)