You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The current error reporting mechanism of the AST transformer catches exceptions, adds the tracebacks in taichi program and re-raises the exception again and again until it is thrown outside the transformer. This makes python generate tracebacks to each exception and shows During handling of the above exception, another exception occurred because the program throws exceptions when processing the exception.
This can be solved by addingfrom None to raise TaichiCompilationError(msg). In this way, only the last traceback will be displayed. However, we may want to preserve the initial traceback if the error is raised from outside the AST transformer (for example, a python function outside the transformer or some malfunctioning taichi internal functions) like the following part from the example.
Traceback (most recent call last):
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 23, in __call__
return method(ctx, node)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 353, in build_Call
node.ptr = node.func.ptr(*args, **keywords)
File "/home/lin/tmp/test.py", line 4, in baz
raise RuntimeError("an error")
RuntimeError: an error
[Taichi] version 0.8.8, llvm 10.0.0, commit 6ef37747, linux, python 3.9.7
[Taichi] Starting on arch=x64
Traceback (most recent call last):
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 23, in __call__
return method(ctx, node)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 353, in build_Call
node.ptr = node.func.ptr(*args, **keywords)
File "/home/lin/tmp/test.py", line 4, in baz
raise RuntimeError("an error")
RuntimeError: an error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 23, in __call__
return method(ctx, node)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 353, in build_Call
node.ptr = node.func.ptr(*args, **keywords)
File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 58, in decorated
return fun.__call__(*args)
File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 177, in __call__
return transform_tree(tree, ctx)
File "/home/lin/taichi2/python/taichi/lang/ast/transform.py", line 9, in transform_tree
ASTTransformer()(ctx, tree)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 26, in __call__
raise e
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 23, in __call__
return method(ctx, node)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 471, in build_Module
build_stmt(ctx, stmt)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 26, in __call__
raise e
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 23, in __call__
return method(ctx, node)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 441, in build_FunctionDef
build_stmts(ctx, node.body)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 1059, in build_stmts
build_stmt(ctx, stmt)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 26, in __call__
raise e
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 23, in __call__
return method(ctx, node)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 940, in build_Expr
build_stmt(ctx, node.value)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 32, in __call__
raise TaichiCompilationError(msg)
taichi.lang.exception.TaichiCompilationError: On line 8 of file "/home/lin/tmp/test.py":
baz()
^^^^^
RuntimeError: an error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/lin/tmp/test.py", line 14, in <module>
print(foo())
File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 703, in wrapped
return primal(*args, **kwargs)
File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 631, in __call__
key = self.ensure_compiled(*args)
File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 617, in ensure_compiled
self.materialize(key=key, args=args, arg_features=arg_features)
File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 463, in materialize
taichi_kernel = _ti_core.create_kernel(taichi_ast_generator,
File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 458, in taichi_ast_generator
transform_tree(tree, ctx)
File "/home/lin/taichi2/python/taichi/lang/ast/transform.py", line 9, in transform_tree
ASTTransformer()(ctx, tree)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 26, in __call__
raise e
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 23, in __call__
return method(ctx, node)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 471, in build_Module
build_stmt(ctx, stmt)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 26, in __call__
raise e
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 23, in __call__
return method(ctx, node)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 441, in build_FunctionDef
build_stmts(ctx, node.body)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 1059, in build_stmts
build_stmt(ctx, stmt)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 26, in __call__
raise e
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 23, in __call__
return method(ctx, node)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 940, in build_Expr
build_stmt(ctx, node.value)
File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 32, in __call__
raise TaichiCompilationError(msg)
taichi.lang.exception.TaichiCompilationError: On line 12 of file "/home/lin/tmp/test.py":
bar()
^^^^^
On line 8 of file "/home/lin/tmp/test.py":
baz()
^^^^^
RuntimeError: an error
The text was updated successfully, but these errors were encountered:
Describe the bug
The current error reporting mechanism of the AST transformer catches exceptions, adds the tracebacks in taichi program and re-raises the exception again and again until it is thrown outside the transformer. This makes python generate tracebacks to each exception and shows
During handling of the above exception, another exception occurred
because the program throws exceptions when processing the exception.This can be solved by adding
from None
toraise TaichiCompilationError(msg)
. In this way, only the last traceback will be displayed. However, we may want to preserve the initial traceback if the error is raised from outside the AST transformer (for example, a python function outside the transformer or some malfunctioning taichi internal functions) like the following part from the example.To Reproduce
Log/Screenshots
The text was updated successfully, but these errors were encountered: