[Git][reproducible-builds/diffoscope][master] Wrap jsondiff calls with a try-except to prevent fatal errors. (Closes: #903447, #903449)

Chris Lamb gitlab at salsa.debian.org
Fri Jul 20 16:43:38 CEST 2018


Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
794f8152 by Chris Lamb at 2018-07-20T22:42:49+08:00
Wrap jsondiff calls with a try-except to prevent fatal errors. (Closes: #903447, #903449)

- - - - -


1 changed file:

- diffoscope/comparators/json.py


Changes:

=====================================
diffoscope/comparators/json.py
=====================================
--- a/diffoscope/comparators/json.py
+++ b/diffoscope/comparators/json.py
@@ -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'):



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/794f8152844550c35ab55d1d892995da1e8739f7

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/794f8152844550c35ab55d1d892995da1e8739f7
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20180720/2afc42db/attachment.html>


More information about the rb-commits mailing list