Commit 794f8152 authored by Chris Lamb's avatar Chris Lamb

Wrap jsondiff calls with a try-except to prevent fatal errors. (Closes: #903447, #903449)

parent 977e4870
Pipeline #13988 failed with stage
in 10 minutes 14 seconds
......@@ -66,18 +66,7 @@ class JSONFile(File):
)
if difference:
if jsondiff is not None:
a = getattr(self, 'parsed', {})
b = getattr(other, 'parsed', {})
diff = {repr(x): y for x, y in jsondiff.diff(a, b).items()}
difference.add_comment("Similarity: {}%".format(
jsondiff.similarity(a, b),
))
difference.add_comment("Differences: {}".format(
json.dumps(diff, indent=2, sort_keys=True),
))
self.compare_with_jsondiff(difference, other)
return [difference]
......@@ -91,6 +80,26 @@ class JSONFile(File):
return [difference]
def compare_with_jsondiff(self, difference, other):
if jsondiff is None:
return
a = getattr(self, 'parsed', {})
b = getattr(other, 'parsed', {})
try:
diff = {repr(x): y for x, y in jsondiff.diff(a, b).items()}
except Exception:
return
difference.add_comment("Similarity: {}%".format(
jsondiff.similarity(a, b),
))
difference.add_comment("Differences: {}".format(
json.dumps(diff, indent=2, sort_keys=True),
))
@staticmethod
def dumps(file, sort_keys=True):
if not hasattr(file, 'parsed'):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment