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

Dylan Baker baker.dylan.c at gmail.com
Wed Jan 21 10:16:03 PST 2015


simplejson.JSONDecodeError is a child of ValueError, we can just change
the error to ValueError and it will work fine for both.

On Wednesday, January 21, 2015 04:00:33 PM Thomas Wood wrote:
> 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
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20150121/ee06dcaa/attachment.sig>


More information about the Piglit mailing list