From cfc00bb4671fe822340d19fb3329869ace9d5cff Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Mon, 9 Dec 2024 13:31:23 +0100 Subject: [PATCH] Fix formatting of nodes with no non-error children When formatting a `Node`'s child we allowed omitting passing in of the child to format. In that case the user would pass a `None` child and we would attempt to default to formatting the next non-error child. The helper we used to get that child could still return `None` (in case there were only error children remaining, or on incorrect use of the function when the node had no children), but we never handled that case; instead we would have surfaced an `AttributeError` like ``` AttributeError: 'NoneType' object has no attribute 'prev_error_siblings' ``` With this path we explicitly skip any child formatting if we found no child to be formatted. --- zeekscript/formatter.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zeekscript/formatter.py b/zeekscript/formatter.py index bbbea2b..8c7128e 100644 --- a/zeekscript/formatter.py +++ b/zeekscript/formatter.py @@ -149,6 +149,8 @@ def _format_child_impl(self, node, indent, hints=None): def _format_child(self, child=None, indent=False, hints=None): if child is None: child = self._next_child() + if child is None: + return # XXX Pretty subtle that we handle the child's surrounding context here, # in the parent. Might have to refactor in the future.