[Piglit] [PATCH] results.py: avoid an attribute error when using the json module

Thomas Wood thomas.wood at intel.com
Wed Jan 21 08:00:33 PST 2015


The json module raises a ValueError if load() encounters a problem with
the data, but the simplejson module raises a JSONDecodeError exception,
which is not present in the json module. Therefore, check for ValueError
first to avoid an attribute error.

Signed-off-by: Thomas Wood <thomas.wood at intel.com>
---
 framework/results.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/framework/results.py b/framework/results.py
index 5819af5..f1b1b50 100644
--- a/framework/results.py
+++ b/framework/results.py
@@ -167,6 +167,13 @@ class TestrunResult(object):
             with open(os.path.join(results_dir, 'tests', file_), 'r') as f:
                 try:
                     test = json.load(f)
+                # The json module raises a ValueError if load() encounters a
+                # problem with the data, but the simplejson module raises a
+                # JSONDecodeError exception, which is not present in the json
+                # module. Therefore, check for ValueError first to avoid an
+                # attribute error.
+                except ValueError:
+                    continue
                 except json.JSONDecodeError:
                     continue
             # XXX: There has to be a better way to get a single key: value out
-- 
2.1.0



More information about the Piglit mailing list