biomejs/biome · error

found a token with no parent

Error message

found a token with no parent

What it means

Panic in the JavaScript format-on-type handler (javascript.rs:1655). After locating the token at the cursor, the handler calls token.parent(); tokens returned by token_at_offset always belong to the tree and have a parent node, because a rowan tree's root is a node. This panic is a defensive assertion for detached/token-rooted trees that the parser cannot produce.

Source

Thrown at crates/biome_service/src/file_handlers/javascript.rs:1690

        // File is empty, do nothing
        TokenAtOffset::None => panic!("empty file"),
        TokenAtOffset::Single(token) => token,
        // The cursor should be right after the closing character that was just typed,
        // select the previous token as the correct one
        TokenAtOffset::Between(token, _) => token,
    };

    if token.text_trimmed_range().end() != offset {
        return Ok(format_on_type_noop(offset));
    }

    if !matches_on_type_char(token.text_trimmed()) {
        return Ok(format_on_type_noop(offset));
    }

    let root_node = match token.parent() {
        Some(node) => node,
        None => panic!("found a token with no parent"),
    };

    if root_node
        .ancestors()
        .any(|node: JsSyntaxNode| node.kind().is_bogus())
    {
        return Ok(format_on_type_noop(offset));
    }

    let printed = biome_js_formatter::format_range(options, &tree, root_node.text_trimmed_range())?;
    Ok(printed)
}

fn format_embedded(
    biome_path: &BiomePath,
    document_file_source: &DocumentFileSource,
    parse: super::ParsedOrigin,
    settings: &SettingsWithEditor,

View on GitHub (pinned to 0fca643d22)

Solutions

  1. Update to the latest Biome release
  2. File an issue with a reproducer at https://github.com/biomejs/biome/issues if reproducible
  3. Embedders: run on-type formatting under catch_unwind and fall back to no formatting
Defensive patterns

Strategy: fallback

Try / catch

// LSP client - degrade to no formatting if the server panics
try {
  await client.sendRequest('textDocument/onTypeFormatted', params);
} catch {
  // swallow: on-type formatting must never break editing
}

Prevention

When it happens

Trigger: Not reachable through normal editor traffic; would require a detached token or a token as tree root.

Common situations: Practically never seen; theoretical unless syntax trees are hand-built or parser internals are modified.

Related errors


AI-assisted analysis of biomejs/biome@0fca643d22 (2026-08-20). Data as JSON: /api/errors/5d73f93d2a46238f. Report an issue: GitHub.