diff options
author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2021-04-19 21:36:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-19 21:36:17 +0200 |
commit | 00a2394ec7d5aedc3e768260bf1073c85821430e (patch) | |
tree | 1670605b23150f6302d87885cb1fa730b7a507d1 | |
parent | e826cec346db036ba24730d3c983d3c0b2668d60 (diff) | |
download | pylint-git-00a2394ec7d5aedc3e768260bf1073c85821430e.tar.gz |
Improve exception debugging (#4381)
-rw-r--r-- | pylint/utils/ast_walker.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/pylint/utils/ast_walker.py b/pylint/utils/ast_walker.py index e9f801092..6ad2f953f 100644 --- a/pylint/utils/ast_walker.py +++ b/pylint/utils/ast_walker.py @@ -13,6 +13,7 @@ class ASTWalker: self.visit_events = collections.defaultdict(list) self.leave_events = collections.defaultdict(list) self.linter = linter + self.exception_msg = False def _is_method_enabled(self, method): if not hasattr(method, "checks_msgs"): @@ -65,13 +66,20 @@ class ASTWalker: visit_events = self.visit_events.get(cid, ()) leave_events = self.leave_events.get(cid, ()) - if astroid.is_statement: - self.nbstatements += 1 - # generate events for this node on each checker - for callback in visit_events or (): - callback(astroid) - # recurse on children - for child in astroid.get_children(): - self.walk(child) - for callback in leave_events or (): - callback(astroid) + try: + if astroid.is_statement: + self.nbstatements += 1 + # generate events for this node on each checker + for callback in visit_events or (): + callback(astroid) + # recurse on children + for child in astroid.get_children(): + self.walk(child) + for callback in leave_events or (): + callback(astroid) + except Exception: + if self.exception_msg is False: + file = getattr(astroid.root(), "file", None) + print(f"Exception on node {repr(astroid)} in file '{file}'") + self.exception_msg = True + raise |