biomejs/biome · error
empty file
Error message
empty file
What it means
Panic in the JavaScript format-on-type handler (javascript.rs:1638). For a textDocument/onTypeFormatted request, Biome resolves the token under the cursor with tree.token_at_offset(offset); TokenAtOffset::None means the parsed tree contains no tokens, i.e. the document is empty. Despite the 'File is empty, do nothing' comment, the arm panics, so on-type formatting an empty JS/TS/JSX document crashes this path.
Source
Thrown at crates/biome_service/src/file_handlers/javascript.rs:1673
settings: &SettingsWithEditor,
offset: TextSize,
workspace_db: WorkspaceDb,
) -> Result<Printed, WorkspaceError> {
let options = resolve_format_options(path, document_file_source, settings, &workspace_db);
debug!("{:?}", &options);
let tree = parse.syntax(&workspace_db);
let range = tree.text_range_with_trivia();
if offset < range.start() || offset > range.end() {
return Err(WorkspaceError::FormatError(FormatError::RangeError {
input: TextRange::at(offset, TextSize::from(0)),
tree: range,
}));
}
let token = match tree.token_at_offset(offset) {
// 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"),
};View on GitHub (pinned to 0fca643d22)
Solutions
- Update Biome - check release notes for a fix and report at https://github.com/biomejs/biome/issues if still present
- Client-side guard: only send textDocument/onTypeFormatted when document.getText().length > 0
- In a fork: TokenAtOffset::None => return Ok(format_on_type_noop(offset))
Example fix
// before
TokenAtOffset::None => panic!("empty file"),
// after
TokenAtOffset::None => return Ok(format_on_type_noop(offset)), Defensive patterns
Strategy: validation
Validate before calling
// LSP client (TypeScript) - skip on-type formatting for empty JS/TS files if (document.getText().length === 0) return; // avoid the server-side panic path
Type guard
const isEmptyDocument = (document: TextDocument): boolean => document.getText().length === 0;
Prevention
- Guard every textDocument/onTypeFormatted send with a non-empty check - empty buffers are common (untitled files, full deletions)
- Do not register onTypeFormatting until the first content change of a session
- Keep the Biome extension/server updated; this panic family affects all language handlers
When it happens
Trigger: An LSP client sends onTypeFormatted for a zero-length .js/.ts/.jsx file: offset 0 passes the range guard over tree range 0..0, token_at_offset(0) returns None, and the panic fires. Any non-empty file returns at least a token and avoids this arm.
Common situations: The most-hit variant of this bug since JS files dominate Biome usage: editors firing on-type format on empty buffers (new untitled files, cleared documents), aggressive format-on-key plugins, or LSP test harnesses.
Related errors
AI-assisted analysis of biomejs/biome@0fca643d22 (2026-08-20).
Data as JSON: /api/errors/eaa7267d71c6b2b9.
Report an issue: GitHub.