{"record":{"id":"5d73f93d2a46238f","repo":"biomejs/biome","slug":"found-a-token-with-no-parent-5d73f9","errorCode":null,"errorMessage":"found a token with no parent","messagePattern":"found a token with no parent","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/biome_service/src/file_handlers/javascript.rs","lineNumber":1690,"sourceCode":"        // File is empty, do nothing\n        TokenAtOffset::None => panic!(\"empty file\"),\n        TokenAtOffset::Single(token) => token,\n        // The cursor should be right after the closing character that was just typed,\n        // select the previous token as the correct one\n        TokenAtOffset::Between(token, _) => token,\n    };\n\n    if token.text_trimmed_range().end() != offset {\n        return Ok(format_on_type_noop(offset));\n    }\n\n    if !matches_on_type_char(token.text_trimmed()) {\n        return Ok(format_on_type_noop(offset));\n    }\n\n    let root_node = match token.parent() {\n        Some(node) => node,\n        None => panic!(\"found a token with no parent\"),\n    };\n\n    if root_node\n        .ancestors()\n        .any(|node: JsSyntaxNode| node.kind().is_bogus())\n    {\n        return Ok(format_on_type_noop(offset));\n    }\n\n    let printed = biome_js_formatter::format_range(options, &tree, root_node.text_trimmed_range())?;\n    Ok(printed)\n}\n\nfn format_embedded(\n    biome_path: &BiomePath,\n    document_file_source: &DocumentFileSource,\n    parse: super::ParsedOrigin,\n    settings: &SettingsWithEditor,","sourceCodeStart":1672,"sourceCodeEnd":1708,"githubUrl":"https://github.com/biomejs/biome/blob/0fca643d22845c28e0e0b7375013155e3f80717f/crates/biome_service/src/file_handlers/javascript.rs#L1672-L1708","documentation":"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.","triggerScenarios":"Not reachable through normal editor traffic; would require a detached token or a token as tree root.","commonSituations":"Practically never seen; theoretical unless syntax trees are hand-built or parser internals are modified.","solutions":["Update to the latest Biome release","File an issue with a reproducer at https://github.com/biomejs/biome/issues if reproducible","Embedders: run on-type formatting under catch_unwind and fall back to no formatting"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// LSP client - degrade to no formatting if the server panics\ntry {\n  await client.sendRequest('textDocument/onTypeFormatted', params);\n} catch {\n  // swallow: on-type formatting must never break editing\n}","preventionTips":["Make on-type formatting strictly optional in editor integrations","Pin a stable Biome server version per extension release","Report the document + keystroke upstream if this fires"],"tags":["javascript","lsp","format-on-type","panic","defensive-check"],"backgroundTag":"syntax-token-no-parent","analyzedSha":"0fca643d22845c28e0e0b7375013155e3f80717f","analyzedAt":"2026-08-20T00:25:09.682Z","contentChangedAt":"2026-08-20T00:25:09.682Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}