Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Error] Shorten the length of traceback of exceptions thrown by ASTTransformer #3873

Merged
merged 2 commits into from
Jan 5, 2022

Conversation

lin-hitonami
Copy link
Contributor

@lin-hitonami lin-hitonami commented Dec 24, 2021

Related issue = fixes #3785
Error message of the program in the issue after this PR:

Traceback (most recent call last):
  File "/home/lin/tmp/./test.py", line 15, in <module>
    foo()
  File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 715, in wrapped
    return primal(*args, **kwargs)
  File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 643, in __call__
    key = self.ensure_compiled(*args)
  File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 629, in ensure_compiled
    self.materialize(key=key, args=args, arg_features=arg_features)
  File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 475, in materialize
    taichi_kernel = _ti_core.create_kernel(taichi_ast_generator,
  File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 465, in taichi_ast_generator
    transform_tree(tree, ctx)
  File "/home/lin/taichi2/python/taichi/lang/ast/transform.py", line 8, in transform_tree
    ASTTransformer()(ctx, tree)
  File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 27, in __call__
    raise e.with_traceback(None)
taichi.lang.exception.TaichiCompilationError: On line 13 of file "/home/lin/tmp/./test.py":
    bar()
    ^^^^^
On line 9 of file "/home/lin/tmp/./test.py":
    baz()
    ^^^^^
Traceback (most recent call last):
  File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 24, in __call__
    return method(ctx, node)
  File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer.py", line 360, in build_Call
    node.ptr = node.func.ptr(*args, **keywords)
  File "/home/lin/tmp/./test.py", line 5, in baz
    raise RuntimeError("an error")
RuntimeError: an error

If a TaichiSyntaxError is thrown, which means the error is thrown by the transformer, the exception type will remain TaichiSyntaxError, and the original traceback at the bottom will not appear because it is not necessary.
For the following program,

import taichi as ti
ti.init()

@ti.kernel
def foo():
    1 in 2

foo()

The traceback looks like this.

Traceback (most recent call last):
  File "/home/lin/tmp/./test.py", line 8, in <module>
    foo()
  File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 715, in wrapped
    return primal(*args, **kwargs)
  File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 643, in __call__
    key = self.ensure_compiled(*args)
  File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 629, in ensure_compiled
    self.materialize(key=key, args=args, arg_features=arg_features)
  File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 475, in materialize
    taichi_kernel = _ti_core.create_kernel(taichi_ast_generator,
  File "/home/lin/taichi2/python/taichi/lang/kernel_impl.py", line 465, in taichi_ast_generator
    transform_tree(tree, ctx)
  File "/home/lin/taichi2/python/taichi/lang/ast/transform.py", line 8, in transform_tree
    ASTTransformer()(ctx, tree)
  File "/home/lin/taichi2/python/taichi/lang/ast/ast_transformer_utils.py", line 27, in __call__
    raise e.with_traceback(None)
taichi.lang.exception.TaichiSyntaxError: On line 6 of file "/home/lin/tmp/./test.py":
    1 in 2
    ^^^^^^
"In" is only supported inside `ti.static`.

@netlify
Copy link

netlify bot commented Dec 24, 2021

✔️ Deploy Preview for jovial-fermat-aa59dc ready!

🔨 Explore the source changes: 18f990b

🔍 Inspect the deploy log: https://app.netlify.com/sites/jovial-fermat-aa59dc/deploys/61d505b20424d600089ad912

😎 Browse the preview: https://deploy-preview-3873--jovial-fermat-aa59dc.netlify.app

@lin-hitonami lin-hitonami changed the title [Error] shorten the length of traceback of exceptions thrown by ASTTransformer [Error] Shorten the length of traceback of exceptions thrown by ASTTransformer Dec 24, 2021
Copy link
Contributor

@strongoier strongoier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lin-hitonami lin-hitonami merged commit 13271d6 into taichi-dev:master Jan 5, 2022
@lin-hitonami lin-hitonami deleted the exc branch January 7, 2022 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-raised exceptions generates redundant tracebacks in AST transformer
2 participants