shader_runner: Take spirv_replaces_glsl into account for current_config
[piglit.git] / framework / exceptions.py
blob6ca3ed773039d431174841a94ab9c413450ef678
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
19 # SOFTWARE.
21 """Exception and error classes for piglit, and exception handlers."""
23 from __future__ import print_function, absolute_import, division
24 import sys
25 import functools
27 from framework import compat
29 __all__ = [
30 'PiglitInternalError',
31 'PiglitFatalError',
32 'PiglitException',
33 'PiglitAbort',
34 'handler',
39 def handler(func):
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
44 generic Exceptions
46 """
48 @functools.wraps(func)
49 def _inner(*args, **kwargs):
50 try:
51 func(*args, **kwargs)
52 except PiglitFatalError as e:
53 print('Fatal Error: {}'.format(str(e)), file=sys.stderr)
54 sys.exit(1)
55 except PiglitAbort as e:
56 print('Aborting Piglit execution: {}'.format(str(e)),
57 file=sys.stderr)
58 sys.exit(3)
59 except PiglitUserError as e:
60 print('User error: {}'.format(str(e)), file=sys.stderr)
61 sys.exit(1)
63 return _inner
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.
73 """
74 def __str__(self):
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.
85 """
86 def __str__(self):
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.
97 """
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.