Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 biome_grit_parser::parse_grit panics #4825

Closed
1 task done
Arian8j2 opened this issue Jan 2, 2025 · 3 comments · Fixed by #4937
Closed
1 task done

🐛 biome_grit_parser::parse_grit panics #4825

Arian8j2 opened this issue Jan 2, 2025 · 3 comments · Fixed by #4937
Labels
A-Parser Area: parser good first issue Good for newcomers L-Grit Language: GritQL S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@Arian8j2
Copy link

Arian8j2 commented Jan 2, 2025

Environment information

CLI:
  Version:                      0.0.0
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           unset
  JS_RUNTIME_NAME:              unset
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       unset

Workspace:
  Open Documents:               0

I compiled the `biome` from `6ea885f0cec47a6db48d662cbd828f4f335209ba` commit

What happened?

  1. create a file named suspect1.grit and put this grit query in it:
engine marzano(0.1)
language python

`$var in $dict.keys()` => `$var in $dict`
  1. then running biome format will result in:
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: /path_to_biome/crates/biome_parser/src/diagnostic.rs:350:14
Thread Name: biome::worker_23
Message: Expected token to be a punctuation or keyword.

/path_to_current_folder/suspect1.grit internalError/panic  INTERNAL  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ processing panicked: Expected token to be a punctuation or keyword.

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


Checked 0 files in 1010µs. No fixes applied.
internalError/io ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ No files were processed in the specified paths.

i traced the panic from calling biome_grit_parser::parse_grit and the result is this:

stack backtrace:
   4: core::option::Option<T>::expect
             at /.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:933:21
   5: biome_parser::diagnostic::expected_token
             at /.cargo/git/checkouts/biome-d49ce8898b420a50/6ea885f/crates/biome_parser/src/diagnostic.rs:348:9
   6: biome_parser::Parser::expect
             at /.cargo/git/checkouts/biome-d49ce8898b420a50/6ea885f/crates/biome_parser/src/lib.rs:422:24
   7: biome_grit_parser::parser::parse_root
             at /.cargo/git/checkouts/biome-d49ce8898b420a50/6ea885f/crates/biome_grit_parser/src/parser/mod.rs:91:5
   8: biome_grit_parser::parse_grit_with_cache::{{closure}}
             at /.cargo/git/checkouts/biome-d49ce8898b420a50/6ea885f/crates/biome_grit_parser/src/lib.rs:26:9
   9: tracing::span::Span::in_scope
             at /.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-0.1.41/src/span.rs:1102:9
  10: biome_grit_parser::parse_grit_with_cache
             at /.cargo/git/checkouts/biome-d49ce8898b420a50/6ea885f/crates/biome_grit_parser/src/lib.rs:23:5
  11: biome_grit_parser::parse_grit
             at /.cargo/git/checkouts/biome-d49ce8898b420a50/6ea885f/crates/biome_grit_parser/src/lib.rs:18:5

it's not just this pattern that makes it panic, there are lots of other patterns that trigger it too, you can test patterns in stdlib

Expected result

It shouldn't panic

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@Arian8j2 Arian8j2 added the S-Needs triage Status: this issue needs to be triaged label Jan 2, 2025
@ematipico
Copy link
Member

Here's a reproduction.

@Arian8j2, please next time, provide one :)

@ematipico ematipico added A-Parser Area: parser S-Bug-confirmed Status: report has been confirmed as a valid bug L-Grit Language: GritQL labels Jan 2, 2025
@github-actions github-actions bot removed the S-Needs triage Status: this issue needs to be triaged label Jan 2, 2025
@arendjr
Copy link
Contributor

arendjr commented Jan 2, 2025

I think this happens because I made a bit of a shortcut with the parser, which only supports engine biome and the languages we support in Biome. But I agree it’s an unfortunate choice if someone wants to use our formatter with Grit files not intended for Biome plugins, which is a totally valid use case.

Fortunately it shouldn’t be too hard to allow arbitrary engine and languages names, but it requires a small extension to the grammar.

@arendjr arendjr added the good first issue Good for newcomers label Jan 2, 2025
@morgante
Copy link
Contributor

I'm working on this, should have a PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Parser Area: parser good first issue Good for newcomers L-Grit Language: GritQL S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants