Skip to content

Commit

Permalink
add rendering of error in dispatch (apache#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
junrushao authored Jul 2, 2022
1 parent 541ac01 commit ee83019
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions python/tvm/script/parse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@
}


def _dispatch_wrapper(func: dispatch.ParseMethod) -> dispatch.ParseMethod:
def _wrapper(self: Parser, node: doc.AST) -> None:
try:
return func(self, node)
except Exception as e:
self.report_error(node, str(e))
raise

return _wrapper


def _dispatch(self: "Parser", type_name: str) -> dispatch.ParseMethod:
for token in [self.dispatch_tokens[-1], "default"]:
func = dispatch.get(token=token, type_name=type_name, default=None)
if func is not None:
return func
return lambda self, node: self.generic_visit(node)
return _dispatch_wrapper(func)
return _dispatch_wrapper(lambda self, node: self.generic_visit(node))


class Parser(doc.NodeVisitor):
Expand Down

0 comments on commit ee83019

Please sign in to comment.