Formats the header, traceback and exception message for a single exception. This may be called multiple times by Python 3 exception chaining (PEP 3134).
(
self,
etype: type,
evalue: Optional[BaseException],
etb: Optional[TracebackType],
context: int,
tb_offset: Optional[int],
)
| 277 | ] |
| 278 | |
| 279 | def format_exception_as_a_whole( |
| 280 | self, |
| 281 | etype: type, |
| 282 | evalue: Optional[BaseException], |
| 283 | etb: Optional[TracebackType], |
| 284 | context: int, |
| 285 | tb_offset: Optional[int], |
| 286 | ) -> list[list[str]]: |
| 287 | """Formats the header, traceback and exception message for a single exception. |
| 288 | |
| 289 | This may be called multiple times by Python 3 exception chaining |
| 290 | (PEP 3134). |
| 291 | """ |
| 292 | # some locals |
| 293 | orig_etype = etype |
| 294 | try: |
| 295 | etype = etype.__name__ # type: ignore[assignment] |
| 296 | except AttributeError: |
| 297 | pass |
| 298 | |
| 299 | tb_offset = self.tb_offset if tb_offset is None else tb_offset |
| 300 | assert isinstance(tb_offset, int) |
| 301 | head = self.prepare_header(str(etype)) |
| 302 | assert context == 1, context |
| 303 | records = self.get_records(etb, context, tb_offset) if etb else [] |
| 304 | |
| 305 | frames = [] |
| 306 | skipped = 0 |
| 307 | nskipped = len(records) - 1 |
| 308 | frames.append(self.format_record(records[0])) |
| 309 | if nskipped: |
| 310 | frames.append( |
| 311 | theme_table[self._theme_name].format( |
| 312 | [ |
| 313 | (Token, "\n"), |
| 314 | (Token, " "), |
| 315 | (Token, "[... %s skipped frames]" % nskipped), |
| 316 | (Token, "\n"), |
| 317 | (Token, "\n"), |
| 318 | ] |
| 319 | ) |
| 320 | ) |
| 321 | |
| 322 | formatted_exception = self.format_exception(etype, evalue) |
| 323 | return [[head] + frames + formatted_exception] |
| 324 | |
| 325 | def get_records(self, etb: TracebackType, context: int, tb_offset: int) -> Any: |
| 326 | assert context == 1, context |
no test coverage detected