{"record":{"id":"4ec20aeb4b186af6","repo":"biomejs/biome","slug":"empty-file","errorCode":null,"errorMessage":"empty file","messagePattern":"empty file","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/biome_service/src/file_handlers/css.rs","lineNumber":645,"sourceCode":"    settings: &SettingsWithEditor,\n    offset: TextSize,\n    workspace_db: WorkspaceDb,\n) -> Result<Printed, WorkspaceError> {\n    let options = resolve_format_options(biome_path, document_file_source, settings, &workspace_db);\n\n    let tree = parse.syntax(&workspace_db);\n\n    let range = tree.text_range_with_trivia();\n    if offset < range.start() || offset > range.end() {\n        return Err(WorkspaceError::FormatError(FormatError::RangeError {\n            input: TextRange::at(offset, TextSize::from(0)),\n            tree: range,\n        }));\n    }\n\n    let token = match tree.token_at_offset(offset) {\n        // 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    };","sourceCodeStart":627,"sourceCodeEnd":663,"githubUrl":"https://github.com/biomejs/biome/blob/405dedb0ff65dd29927faf587f6542e3c29db248/crates/biome_service/src/file_handlers/css.rs#L627-L663","documentation":"Panic inside the CSS format-on-type handler (css.rs:645). When an editor sends a textDocument/onTypeFormatted request, Biome locates the token at the cursor with tree.token_at_offset(offset); TokenAtOffset::None means the tree contains no token at all, i.e. the document is empty. Despite the 'File is empty, do nothing' comment, the arm panics instead of returning a no-op, so an on-type format request against an empty CSS document crashes this code path.","triggerScenarios":"An LSP client sends onTypeFormatted for a CSS document whose text is empty (zero length): the range guard at offset 0 over tree range 0..0 passes, then token_at_offset(0) returns None and panics. Requires the document to contain no tokens; whitespace-only files still return a whitespace token and do not trigger it.","commonSituations":"Editors that fire on-type formatting as soon as a file is opened or after all content is deleted; LSP middleware or bots replaying onTypeFormatted requests; newly-created empty .css files.","solutions":["Update Biome - check newer releases for a fix replacing this panic with a no-op return, and report it at https://github.com/biomejs/biome/issues if still present","On the client side, do not send textDocument/onTypeFormatted while document.getText().length === 0","Return format_on_type_noop(offset) instead of panicking if you maintain a fork: TokenAtOffset::None => return Ok(format_on_type_noop(offset))"],"exampleFix":"// before (crates/biome_service/src/file_handlers/css.rs)\nTokenAtOffset::None => panic!(\"empty file\"),\n\n// after\nTokenAtOffset::None => return Ok(format_on_type_noop(offset)),","handlingStrategy":"validation","validationCode":"// LSP client (TypeScript) - skip on-type formatting for empty documents\nconst text = document.getText();\nif (text.length === 0) return; // do not send textDocument/onTypeFormatted","typeGuard":"const isEmptyDocument = (document: TextDocument): boolean =>\n  document.getText().length === 0;","tryCatchPattern":null,"preventionTips":["Gate onTypeFormatted requests on document.getText().length > 0","Register format-on-type only after the first content change, not on document open","Keep the Biome server updated - empty-file on-type handling is a known panic shape worth tracking upstream"],"tags":["css","lsp","format-on-type","panic","empty-file"],"backgroundTag":"format-on-type-empty-document","analyzedSha":"405dedb0ff65dd29927faf587f6542e3c29db248","analyzedAt":"2026-08-20T00:25:09.682Z","contentChangedAt":"2026-08-20T00:25:09.682Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}