Skip to content
Snippets Groups Projects
Commit 794f8152 authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

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

parent 977e4870
No related branches found
No related tags found
No related merge requests found
Pipeline #13988 failed
......@@ -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'):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment