biomejs/biome · error

Expected enclosing nodes to at least contain the root node.

Error message

Expected enclosing nodes to at least contain the root node.

What it means

Error "Expected enclosing nodes to at least contain the root node." thrown in biomejs/biome.

Source

Thrown at crates/biome_formatter/src/comments/builder.rs:250

        if let Some(following_node) = self.following_node() {
            self.flush_comments(Some(&following_node.clone()));
            self.following_node_index = None;

            // The following node is only set after entering a node
            // That means, following node is only set for the first token of a node.
            // Unset preceding node if this is the first token because the preceding node belongs to the parent.
            self.preceding_node = None;
        }
    }

    fn enclosing_node(&self) -> &SyntaxNode<Style::Language> {
        let element = match self.following_node_index {
            None => self.parents.last(),
            Some(0) => Some(&self.parents[0]),
            Some(index) => Some(&self.parents[index - 1]),
        };

        element.expect("Expected enclosing nodes to at least contain the root node.")
    }

    fn following_node(&self) -> Option<&SyntaxNode<Style::Language>> {
        self.following_node_index.map(|index| {
            self.parents
                .get(index)
                .expect("Expected following node index to point to a valid parent node")
        })
    }

    fn queue_comment(&mut self, comment: DecoratedComment<Style::Language>) {
        self.pending_comments.push(comment);
    }

    fn update_comments(
        comments: &mut [DecoratedComment<Style::Language>],
        position: CommentTextPosition,
        lines_before: u32,

View on GitHub (pinned to 45a19bbf17)

Solutions

  1. This is an internal formatter invariant violation; report it as a Biome bug with the source file that triggered it.
  2. Ensure the node passed to the comments builder belongs to the root's syntax tree.

Example fix

// Report at https://github.com/biomejs/biome/issues with a minimal repro

When it happens

Trigger: Thrown at crates/biome_formatter/src/comments/builder.rs:246 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of biomejs/biome@45a19bbf17 (2026-08-20). Data as JSON: /api/errors/b767346437fec017. Report an issue: GitHub.