1 # Copyright (c) 2015 Intel Corporation
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 """Exception and error classes for piglit, and exception handlers."""
23 from __future__
import print_function
, absolute_import
, division
27 from framework
import compat
30 'PiglitInternalError',
40 """Decorator function for handling errors in an entry point.
42 This will handle expected errors (PiglitFatalError), and unexpected errors,
43 either PiglitInternalErrors or PiglitExceptions, as well as handling
48 @functools.wraps(func
)
49 def _inner(*args
, **kwargs
):
52 except PiglitFatalError
as e
:
53 print('Fatal Error: {}'.format(str(e
)), file=sys
.stderr
)
55 except PiglitAbort
as e
:
56 print('Aborting Piglit execution: {}'.format(str(e
)),
59 except PiglitUserError
as e
:
60 print('User error: {}'.format(str(e
)), file=sys
.stderr
)
66 @compat.python_2_unicode_compatible
67 class PiglitException(Exception):
68 """Class for non-error exceptions.
70 These should *always* be caught. If this class (or any subclass) is
71 uncaught that is a bug in piglit.
75 return (u
'An internal exception that should have been handled was not:'
76 '\n{}'.format(super(PiglitException
, self
).__str
__()))
79 @compat.python_2_unicode_compatible
80 class PiglitInternalError(Exception):
81 """Class for errors in piglit.
83 These should always be handled.
87 return u
'An internal error occurred:\n{}'.format(
88 super(PiglitInternalError
, self
).__str
__())
91 class PiglitFatalError(Exception):
92 """Class for errors in piglit that cannot be recovered from.
94 When this class (or a subclass) is raised it should be raised all the way
95 to the top of the program where it exits.
100 class PiglitUserError(Exception):
101 """Class for user configuration errors.
103 When this class (or a subclass) is raised it should be raised all the way
104 to the top of the program where it exits.
108 class PiglitAbort(Exception):
109 """Class for non-errors that require piglit aborting.
111 When this class (or a subclass) is raised it should be raised all the way
112 to the top of the program where it exits.