Skip to content

Commit 73e7909

Browse files
authored
[TVMScript] Preserve traceback across TVMScript parsing (#15824)
Prior to this commit, exceptions raised during the parsing of TVMScript would be caught and replaced with a new exception. While this does allow the TVMScript location of the error to be included in the exception, it also removes the stack trace of the original error. This commit updates the `Parser.report_error` function to provide the original stack trace alongside the updated exception object.
1 parent 0d68328 commit 73e7909

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

python/tvm/script/parser/core/parser.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,18 @@ def report_error(
522522
msg = "KeyError: " + str(err)
523523
else:
524524
msg = str(err)
525-
self.diag.error(node, msg)
525+
526+
try:
527+
self.diag.error(node, msg)
528+
except Exception as diag_err:
529+
# Calling self.diag.error is guaranteed to throw an
530+
# exception. When shown to a user, this error should
531+
# reference the point of error within the provided
532+
# TVMScript. However, when caught in pdb, the full
533+
# traceback should be available for debugging.
534+
if isinstance(err, Exception):
535+
diag_err = diag_err.with_traceback(err.__traceback__)
536+
raise diag_err
526537

527538
def visit(self, node: doc.AST) -> None:
528539
"""The general visiting method.

0 commit comments

Comments
 (0)