Skip to content

Commit

Permalink
Fix formatting of nodes with no non-error children
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bbannier committed Dec 9, 2024
1 parent 28a883a commit cfc00bb
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions zeekscript/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cfc00bb

Please sign in to comment.