biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
14.19k stars 439 forks source link

🐛 Unexpected error: Tried to cast node with kind JS_EXPRESSION_STATEMENT as `"biome_js_syntax::generated::nodes::AnyJsExpression"` but was unable to cast #1144

Closed marcelpanse closed 8 months ago

marcelpanse commented 9 months ago

Environment information

CLI:
  Version:                      1.4.1
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v18.15.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "pnpm/8.6.2"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 false

Workspace:
  Open Documents:               0

What happened?

I couldn't reproduce it in the playground, but here is my local code that crashes biome: https://biomejs.dev/playground/?code=aQBtAHAAbwByAHQAIABSAGUAYQBjAHQALAAgAHsARgBDACwAIABGAHIAYQBnAG0AZQBuAHQAfQAgAGYAcgBvAG0AIAAnAHIAZQBhAGMAdAAnAAoAaQBtAHAAbwByAHQAIAB7AHUAcwBlAFMAZQBsAGUAYwB0AG8AcgAsACAAdQBzAGUARABpAHMAcABhAHQAYwBoAH0AIABmAHIAbwBtACAAJwByAGUAYQBjAHQALQByAGUAZAB1AHgAJwAKAGkAbQBwAG8AcgB0ACAAewBJAGMAbwBuACwAIABUAG8AbwBsAHQAaQBwAH0AIABmAHIAbwBtACAAJwBAAG0AdQBpAC8AbQBhAHQAZQByAGkAYQBsACcACgBpAG0AcABvAHIAdAAgAHsAcAB1AHMAaAB9ACAAZgByAG8AbQAgACcAYwBvAG4AbgBlAGMAdABlAGQALQByAGUAYQBjAHQALQByAG8AdQB0AGUAcgAnAAoAaQBtAHAAbwByAHQAIAB7AFMAdABhAHQAZQB9ACAAZg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QAaABpAHMAIABmAGUAYQB0AHUAcgBlACAAYgB5ACAAdQBwAGcAcgBhAGQAaQBuAGcAIAB0AG8AIAB0AGgAZQAgAEIAdQBzAGkAbgBlAHMAcwAgAHAAbABhAG4AIgAKACAAIAAgACAAIAAgACAAIABjAGwAYQBzAHMATgBhAG0AZQA9ACIAdAB4AHQALQBwAG8AaQBuAHQAZQByACIACgAgACAAIAAgACAAIAAgACAAbwBuAEMAbABpAGMAawA9AHsAKAApADoAIAB2AG8AaQBkACAAPQA%2BACAAewAKACAAIAAgACAAIAAgACAAIAAgACAAZABpAHMAcABhAHQAYwBoACgAcAB1AHMAaAAoACcALwBlAG4ALwBkAGEAcwBoAGIAbwBhAHIAZAAvAGEAYwBjAG8AdQBuAHQAJwApACkACgAgACAAIAAgACAAIAAgACAAfQB9AAoAIAAgACAAIAAgACAAPgAKACAAIAAgACAAIAAgACAAIAA8AEkAYwBvAG4APgBsAG8AYwBrAF8AbwBwAGUAbgA8AC8ASQBjAG8AbgA%2BAAoAIAAgACAAIAAgACAAPAAvAFQAbwBvAGwAdABpAHAAPgAKACAAIAAgACAAKQAKACAAIAB9ACAAZQBsAHMAZQAgAHsACgAgACAAIAAgAHIAZQB0AHUAcgBuACAAPABGAHIAYQBnAG0AZQBuAHQAPgB7AGMAaABpAGwAZAByAGUAbgB9ADwALwBGAHIAYQBnAG0AZQBuAHQAPgAKACAAIAB9AAoAfQAKAAoAZQB4AHAAbwByAHQAIABkAGUAZgBhAHUAbAB0ACAATABpAG0AaQB0AGUAZABQAGwAYQBuAFQAbwBvAGwAdABpAHAACgA%3D

The error specifically triggers on {children} on this line.
return <Fragment>{children}</Fragment>

This is the error report it spits out:

/usr/local/bin/pnpm biome:fix-file /Users/marcelpanse/Documents/Sources/dashboard/src/components/limitedPlan/LimitedPlanTooltip.tsx

unless@ biome:fix-file /Users/marcelpanse/Documents/Sources/dashboard biome check --apply-unsafe --error-on-warnings --formatter-enabled=true --linter-enabled=true --organize-imports-enabled=true "/Users/marcelpanse/Documents/Sources/dashboard/src/components/limitedPlan/LimitedPlanTooltip.tsx"

Biome encountered an unexpected error

This is a bug in Biome, not an error in your code, and we would appreciate it if you could report it to https://github.com/biomejs/biome/issues/ along with the following information to help us fixing the issue:

Source Location: /Users/runner/work/biome/biome/crates/biome_rowan/src/ast/mod.rs:230:13 Thread Name: biome::worker_0 Message: Tried to cast node with kind JS_EXPRESSION_STATEMENT as "biome_js_syntax::generated::nodes::AnyJsExpression" but was unable to cast

/Users/marcelpanse/Documents/Sources/dashboard/src/components/limitedPlan/LimitedPlanTooltip.tsx internalError/panic INTERNAL ━━━━━━━━━━

× processing panicked: Tried to cast node with kind JS_EXPRESSION_STATEMENT as "biome_js_syntax::generated::nodes::AnyJsExpression" but was unable to cast

! This diagnostic was derived from an internal Biome error. Potential bug, please report it if necessary.

Fixed 1 file(s) in 1976µs

Process finished with exit code 0

Expected result

It should normally lint it

Code of Conduct

UPDATE workaround: Changing the for a or <> solves the problem.

Conaclos commented 9 months ago

Hi! Thanks to report this bug! Do you encounter the bug when you disable the formatter? or the linter?

ematipico commented 9 months ago

Hi! Thanks to report this bug! Do you encounter the bug when you disable the formatter? or the linter?

The issue is probably the code action applied to this snippet:

function name(params) {
  return <Fragment>{children}</Fragment>
}