[v2,10/16] backends: replace error class with generic error

Submitted by Dylan Baker on May 18, 2015, 5:57 p.m.

Details

Message ID 1431971870-20138-11-git-send-email-baker.dylan.c@gmail.com
State New, archived
Headers show

Not browsing as part of any series.

Commit Message

Dylan Baker May 18, 2015, 5:57 p.m.
This allows more exceptions to be caught at the top level exception
handling, requiring fewer try/except blocks in the middle of the code
that exit. This should make the code a little easier to read.

Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
---
 framework/backends/errors.py  | 25 -------------------------
 framework/backends/json.py    |  7 +++----
 framework/programs/summary.py | 12 ++----------
 framework/summary.py          |  6 +-----
 4 files changed, 6 insertions(+), 44 deletions(-)
 delete mode 100644 framework/backends/errors.py

Patch hide | download patch | download mbox

diff --git a/framework/backends/errors.py b/framework/backends/errors.py
deleted file mode 100644
index 150bc19..0000000
--- a/framework/backends/errors.py
+++ /dev/null
@@ -1,25 +0,0 @@ 
-# Copyright (c) 2015 Intel Corporation
-
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-"""Shared errors for the backends."""
-
-
-class ResultsLoadError(Exception):
-    pass
diff --git a/framework/backends/json.py b/framework/backends/json.py
index 4f3624a..9d76c49 100644
--- a/framework/backends/json.py
+++ b/framework/backends/json.py
@@ -31,10 +31,9 @@  try:
 except ImportError:
     import json
 
-from framework import status, results
+from framework import status, results, exceptions
 from .abstract import FileBackend
 from .register import Registry
-from . import errors
 
 __all__ = [
     'REGISTRY',
@@ -191,8 +190,8 @@  def load_results(filename):
         elif os.path.exists(os.path.join(filename, 'main')):
             filepath = os.path.join(filename, 'main')
         else:
-            raise errors.ResultsLoadError('No results found in "{}"'.format(
-                filename))
+            raise exceptions.PiglitFatalError(
+                'No results found in "{}"'.format(filename))
 
     with open(filepath, 'r') as f:
         testrun = _load(f)
diff --git a/framework/programs/summary.py b/framework/programs/summary.py
index 1ec00bc..130d33a 100644
--- a/framework/programs/summary.py
+++ b/framework/programs/summary.py
@@ -165,11 +165,7 @@  def csv(input_):
                         help="JSON results file to be converted")
     args = parser.parse_args(input_)
 
-    try:
-        testrun = backends.load(args.testResults)
-    except backends.errors.ResultsLoadError as e:
-        print('Error: {}'.format(e.message), file=sys.stderr)
-        sys.exit(1)
+    testrun = backends.load(args.testResults)
 
     def write_results(output):
         for name, result in testrun.tests.iteritems():
@@ -200,11 +196,7 @@  def aggregate(input_):
     assert os.path.isdir(args.results_folder)
 
     outfile = os.path.join(args.results_folder, args.output)
-    try:
-        results = backends.load(args.results_folder)
-    except backends.errors.ResultsLoadError as e:
-        print('Error: {}'.format(e.message), file=sys.stderr)
-        sys.exit(1)
+    results = backends.load(args.results_folder)
 
     try:
         # FIXME: This works, it fixes the problem, but it only works because
diff --git a/framework/summary.py b/framework/summary.py
index cad8cc7..14eaf05 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -299,11 +299,7 @@  class Summary:
 
         # Create a Result object for each piglit result and append it to the
         # results list
-        try:
-            self.results = [backends.load(i) for i in resultfiles]
-        except backends.errors.ResultsLoadError as e:
-            print('Error: {}'.format(e.message), file=sys.stderr)
-            sys.exit(1)
+        self.results = [backends.load(i) for i in resultfiles]
 
         self.status = {}
         self.fractions = {}