biomejs/biome · error
empty file
Error message
empty file
What it means
Panic inside the GraphQL format-on-type handler (graphql.rs:523). For a textDocument/onTypeFormatted request, Biome resolves the token at the cursor with tree.token_at_offset(offset); TokenAtOffset::None means the tree has no tokens, i.e. an empty document. The 'File is empty, do nothing' comment is not honored: the arm panics instead of returning a no-op, so on-type formatting an empty GraphQL document crashes this path.
Source
Thrown at crates/biome_service/src/file_handlers/graphql.rs:523
settings: &SettingsWithEditor,
offset: TextSize,
workspace_db: WorkspaceDb,
) -> Result<Printed, WorkspaceError> {
let options = resolve_format_options(biome_path, document_file_source, settings, &workspace_db);
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 405dedb0ff)
Solutions
- Update Biome - if the panic persists, report it at https://github.com/biomejs/biome/issues
- Client-side: skip sending textDocument/onTypeFormatted when the document text is empty
- In a fork, change the arm to 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 GraphQL files if (document.getText().length === 0) return;
Type guard
const isEmptyDocument = (document: TextDocument): boolean => document.getText().length === 0;
Prevention
- Only send textDocument/onTypeFormatted for non-empty documents
- Delay format-on-type registration until the first edit lands in a .graphql file
- Track upstream fixes for the empty-file on-type panic
When it happens
Trigger: An LSP client sends onTypeFormatted for a zero-length .graphql document: the range check at offset 0 over tree range 0..0 passes, token_at_offset(0) yields None, and the panic fires. Files with at least one token (even whitespace) return a token and skip this arm.
Common situations: Editors triggering on-type format on freshly opened empty .graphql/.gql files or after the user deletes all content; automated LSP conformance suites that send onTypeFormatted to empty buffers.
Related errors
AI-assisted analysis of biomejs/biome@405dedb0ff (2026-08-20).
Data as JSON: /api/errors/81fc67fff96bbf60.
Report an issue: GitHub.