Return a nice text document describing the traceback.
(
self,
etype: type,
evalue: Optional[BaseException],
etb: Optional[TracebackType] = None,
tb_offset: Optional[int] = None,
context: int = 5,
)
| 936 | return FIs |
| 937 | |
| 938 | def structured_traceback( |
| 939 | self, |
| 940 | etype: type, |
| 941 | evalue: Optional[BaseException], |
| 942 | etb: Optional[TracebackType] = None, |
| 943 | tb_offset: Optional[int] = None, |
| 944 | context: int = 5, |
| 945 | ) -> list[str]: |
| 946 | """Return a nice text document describing the traceback.""" |
| 947 | formatted_exceptions: list[list[str]] = self.format_exception_as_a_whole( |
| 948 | etype, evalue, etb, context, tb_offset |
| 949 | ) |
| 950 | |
| 951 | termsize = min(75, get_terminal_size()[0]) |
| 952 | theme = theme_table[self._theme_name] |
| 953 | head: str = theme.format( |
| 954 | [ |
| 955 | ( |
| 956 | Token.Topline, |
| 957 | theme.symbols["top_line"] * termsize, |
| 958 | ), |
| 959 | ] |
| 960 | ) |
| 961 | structured_traceback_parts: list[str] = [head] |
| 962 | chained_exceptions_tb_offset = 0 |
| 963 | lines_of_context = 3 |
| 964 | exception = self.get_parts_of_chained_exception(evalue) |
| 965 | if exception: |
| 966 | assert evalue is not None |
| 967 | formatted_exceptions += self.prepare_chained_exception_message( |
| 968 | evalue.__cause__ |
| 969 | ) |
| 970 | etype, evalue, etb = exception |
| 971 | else: |
| 972 | evalue = None |
| 973 | chained_exc_ids = set() |
| 974 | while evalue: |
| 975 | formatted_exceptions += self.format_exception_as_a_whole( |
| 976 | etype, evalue, etb, lines_of_context, chained_exceptions_tb_offset |
| 977 | ) |
| 978 | exception = self.get_parts_of_chained_exception(evalue) |
| 979 | |
| 980 | if exception and id(exception[1]) not in chained_exc_ids: |
| 981 | chained_exc_ids.add( |
| 982 | id(exception[1]) |
| 983 | ) # trace exception to avoid infinite 'cause' loop |
| 984 | formatted_exceptions += self.prepare_chained_exception_message( |
| 985 | evalue.__cause__ |
| 986 | ) |
| 987 | etype, evalue, etb = exception |
| 988 | else: |
| 989 | evalue = None |
| 990 | |
| 991 | # we want to see exceptions in a reversed order: |
| 992 | # the first exception should be on top |
| 993 | for fx in reversed(formatted_exceptions): |
| 994 | structured_traceback_parts += fx |
| 995 |
nothing calls this directly
no test coverage detected