From 00a2394ec7d5aedc3e768260bf1073c85821430e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 19 Apr 2021 21:36:17 +0200 Subject: Improve exception debugging (#4381) --- pylint/utils/ast_walker.py | 28 ++++++++++++++++++---------- 1 file 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 -- cgit v1.2.1