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 = 1,
)
| 366 | return res2 |
| 367 | |
| 368 | def structured_traceback( |
| 369 | self, |
| 370 | etype: type, |
| 371 | evalue: Optional[BaseException], |
| 372 | etb: Optional[TracebackType] = None, |
| 373 | tb_offset: Optional[int] = None, |
| 374 | context: int = 1, |
| 375 | ) -> list[str]: |
| 376 | """Return a nice text document describing the traceback.""" |
| 377 | assert context > 0 |
| 378 | assert context == 1, context |
| 379 | formatted_exceptions: list[list[str]] = self.format_exception_as_a_whole( |
| 380 | etype, evalue, etb, context, tb_offset |
| 381 | ) |
| 382 | |
| 383 | termsize = min(75, get_terminal_size()[0]) |
| 384 | theme = theme_table[self._theme_name] |
| 385 | structured_traceback_parts: list[str] = [] |
| 386 | chained_exceptions_tb_offset = 0 |
| 387 | lines_of_context = 3 |
| 388 | exception = self.get_parts_of_chained_exception(evalue) |
| 389 | if exception: |
| 390 | assert evalue is not None |
| 391 | formatted_exceptions += self.prepare_chained_exception_message( |
| 392 | evalue.__cause__ |
| 393 | ) |
| 394 | etype, evalue, etb = exception |
| 395 | else: |
| 396 | evalue = None |
| 397 | chained_exc_ids = set() |
| 398 | while evalue: |
| 399 | formatted_exceptions += self.format_exception_as_a_whole( |
| 400 | etype, evalue, etb, lines_of_context, chained_exceptions_tb_offset |
| 401 | ) |
| 402 | exception = self.get_parts_of_chained_exception(evalue) |
| 403 | |
| 404 | if exception and id(exception[1]) not in chained_exc_ids: |
| 405 | chained_exc_ids.add( |
| 406 | id(exception[1]) |
| 407 | ) # trace exception to avoid infinite 'cause' loop |
| 408 | formatted_exceptions += self.prepare_chained_exception_message( |
| 409 | evalue.__cause__ |
| 410 | ) |
| 411 | etype, evalue, etb = exception |
| 412 | else: |
| 413 | evalue = None |
| 414 | |
| 415 | # we want to see exceptions in a reversed order: |
| 416 | # the first exception should be on top |
| 417 | for fx in reversed(formatted_exceptions): |
| 418 | structured_traceback_parts += fx |
| 419 | |
| 420 | return structured_traceback_parts |
| 421 | |
| 422 | def debugger(self, force: bool = False) -> None: |
| 423 | raise RuntimeError("canot rundebugger in Docs mode") |
no test coverage detected