1#     Copyright 2021, Kay Hayen, mailto:kay.hayen@gmail.com
2#
3#     Part of "Nuitka", an optimizing Python compiler that is compatible and
4#     integrates with CPython, but also works on its own.
5#
6#     Licensed under the Apache License, Version 2.0 (the "License");
7#     you may not use this file except in compliance with the License.
8#     You may obtain a copy of the License at
9#
10#        http://www.apache.org/licenses/LICENSE-2.0
11#
12#     Unless required by applicable law or agreed to in writing, software
13#     distributed under the License is distributed on an "AS IS" BASIS,
14#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15#     See the License for the specific language governing permissions and
16#     limitations under the License.
17#
18""" For enhanced bug reporting, these exceptions should be used.
19
20They ideally should point out what it ought to take for reproducing the
21issue when output.
22
23"""
24
25
26class NuitkaErrorBase(Exception):
27    pass
28
29
30class NuitkaNodeError(NuitkaErrorBase):
31
32    # Try to output more information about nodes passed.
33    def __str__(self):
34        try:
35            from nuitka.codegen.Indentation import indented
36
37            parts = [""]
38
39            for arg in self.args:  # false alarm, pylint: disable=I0021,not-an-iterable
40                if hasattr(arg, "asXmlText"):
41                    parts.append(indented("\n%s\n" % arg.asXmlText()))
42                else:
43                    parts.append(str(arg))
44
45            parts.append("")
46            parts.append("The above information should be included in a bug report.")
47
48            return "\n".join(parts)
49        except Exception as e:  # Catch all the things, pylint: disable=broad-except
50            return "<NuitkaNodeError failed with %r>" % e
51
52
53class NuitkaOptimizationError(NuitkaNodeError):
54    pass
55
56
57class NuitkaAssumptionError(AssertionError):
58    pass
59
60
61class NuitkaPluginError(NuitkaErrorBase):
62    pass
63
64
65class NuitkaCodeDeficit(NuitkaErrorBase):
66    pass
67
68
69class NuitkaNodeDesignError(Exception):
70    pass
71
72
73class NuitkaForbiddenImportEncounter(Exception):
74    pass
75
76
77class CodeTooComplexCode(Exception):
78    """The code of the module is too complex.
79
80    It cannot be compiled, with recursive code, and therefore the bytecode
81    should be used instead.
82
83    Example of this is "idnadata".
84    """
85