The error reporting when parsing. Parameters ---------- node : doc.AST The doc AST node with errors. err: Union[Exception, str] The error to report.
(self, node: doc.AST, err: Exception | str)
| 598 | return var_values |
| 599 | |
| 600 | def report_error(self, node: doc.AST, err: Exception | str) -> None: # pylint: disable=no-self-use |
| 601 | """The error reporting when parsing. |
| 602 | |
| 603 | Parameters |
| 604 | ---------- |
| 605 | node : doc.AST |
| 606 | The doc AST node with errors. |
| 607 | |
| 608 | err: Union[Exception, str] |
| 609 | The error to report. |
| 610 | """ |
| 611 | |
| 612 | # If the error is already being raised as a DiagnosticError, |
| 613 | # re-raise it without wrapping it in a DiagnosticContext. |
| 614 | if isinstance(err, DiagnosticError): |
| 615 | raise err |
| 616 | |
| 617 | # Only take the last line of the error message |
| 618 | if isinstance(err, RuntimeError): |
| 619 | lines = list(filter(None, str(err).split("\n"))) |
| 620 | msg = lines[-1] if lines else (str(err) or type(err).__name__) |
| 621 | elif isinstance(err, KeyError): |
| 622 | msg = "KeyError: " + str(err) |
| 623 | else: |
| 624 | msg = str(err) |
| 625 | |
| 626 | try: |
| 627 | self.diag.error(node, msg) |
| 628 | except Exception as diag_err: |
| 629 | # Calling self.diag.error is guaranteed to throw an |
| 630 | # exception. When shown to a user, this error should |
| 631 | # reference the point of error within the provided |
| 632 | # TVMScript. However, when caught in pdb, the full |
| 633 | # traceback should be available for debugging. |
| 634 | if isinstance(err, Exception): |
| 635 | diag_err = diag_err.with_traceback(err.__traceback__) |
| 636 | raise diag_err |
| 637 | |
| 638 | def visit(self, node: doc.AST) -> None: |
| 639 | """The general visiting method. |
no test coverage detected