glsl-1.10: test mesa bug with forward declaration
[piglit.git] / framework / exceptions.py
blob4eb958351bb741598774bdabbaf80bea8f822fa5
1 # coding=utf-8
2 # Copyright (c) 2015, 2019 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
22 """Exception and error classes for piglit, and exception handlers."""
24 import sys
25 import functools
27 __all__ = [
28 'PiglitInternalError',
29 'PiglitFatalError',
30 'PiglitException',
31 'PiglitAbort',
32 'handler',
37 def handler(func):
38 """Decorator function for handling errors in an entry point.
40 This will handle expected errors (PiglitFatalError), and unexpected errors,
41 either PiglitInternalErrors or PiglitExceptions, as well as handling
42 generic Exceptions
44 """
46 @functools.wraps(func)
47 def _inner(*args, **kwargs):
48 try:
49 return func(*args, **kwargs)
50 except PiglitFatalError as e:
51 print('Fatal Error: {}'.format(str(e)), file=sys.stderr)
52 sys.exit(e.exitcode)
53 except PiglitAbort as e:
54 print('Aborting Piglit execution: {}'.format(str(e)),
55 file=sys.stderr)
56 sys.exit(e.exitcode)
57 except PiglitUserError as e:
58 print('User error: {}'.format(str(e)), file=sys.stderr)
59 sys.exit(e.exitcode)
61 return _inner
64 class PiglitBaseException(Exception):
66 """Base class for all piglit exceptions."""
68 def __init__(self, *args, exitcode=1, **kwargs):
69 super().__init__(*args, **kwargs)
70 self.exitcode = exitcode
73 class PiglitException(PiglitBaseException):
74 """Class for non-error exceptions.
76 These should *always* be caught. If this class (or any subclass) is
77 uncaught that is a bug in piglit.
79 """
81 def __str__(self):
82 return ('An internal exception that should have been handled was not:'
83 '\n{}'.format(super(PiglitException, self).__str__()))
86 class PiglitInternalError(PiglitBaseException):
87 """Class for errors in piglit.
89 These should always be handled.
91 """
93 def __str__(self):
94 return 'An internal error occurred:\n{}'.format(
95 super(PiglitInternalError, self).__str__())
98 class PiglitFatalError(PiglitBaseException):
99 """Class for errors in piglit that cannot be recovered from.
101 When this class (or a subclass) is raised it should be raised all the way
102 to the top of the program where it exits.
107 class PiglitUserError(PiglitBaseException):
108 """Class for user configuration errors.
110 When this class (or a subclass) is raised it should be raised all the way
111 to the top of the program where it exits.
115 class PiglitAbort(PiglitBaseException):
116 """Class for non-errors that require piglit aborting.
118 When this class (or a subclass) is raised it should be raised all the way
119 to the top of the program where it exits.
122 def __init__(self, *args, exitcode=3, **kwargs):
123 super().__init__(*args, exitcode=exitcode, **kwargs)