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

🐛 Panic checking json/jsonc file containing triple-quotes #2606

Closed
1 task done
redbmk opened this issue Apr 26, 2024 · 4 comments · Fixed by #2649
Closed
1 task done

🐛 Panic checking json/jsonc file containing triple-quotes #2606

redbmk opened this issue Apr 26, 2024 · 4 comments · Fixed by #2649
Assignees
Labels
A-Parser Area: parser L-JSON Language: JSON and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@redbmk
Copy link

redbmk commented Apr 26, 2024

Environment information

CLI:
  Version:                      1.7.1
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v21.5.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "bun/1.0.30"

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

Workspace:
  Open Documents:               0

What happened?

  1. Create a json or jsonc file containing triple quotes between valid entries. Here's a simple example that shows the issue:
    {
      "hello": "world",
      """
      "asdf": "zxcv",
    }
  2. Run biome check on the file.
  3. Get some expected errors, but also a panic that mentions it's a bug in biome, not the file itself.
    ❯ bunx biome lint test.jsonc
    test.jsonc:3:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    
      × Missing closing quote
      
        1 │ {
        2 │   "hello": "world",
      > 3 │   """
          │     ^
        4 │   "asdf": "zxcv",
        5 │ }
      
      i line breaks here
      
        1 │ {
        2 │   "hello": "world",
      > 3 │   """
          │      
      > 4 │   "asdf": "zxcv",
    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_text_size/src/range.rs:50:9
    Thread Name: main
    Message: assertion failed: start <= end
    

Expected result

I would expect to see the errors it does report, possibly some others, but not the message about biome encountering an unexpected error. It sounds like Biome bailed out early.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@Sec-ant
Copy link
Member

Sec-ant commented Apr 26, 2024

This is probably a duplicate of #2357. Do you have nursery lint rules enabled?

@redbmk
Copy link
Author

redbmk commented Apr 26, 2024

I haven't enabled any of them, just the recommended rules. I just tried creating a new config using bunx @biomejs/biome init and get the same error, but I don't actually see a panic for the one reported in that issue.

❯ cat biome.json
{
        "$schema": "https://biomejs.dev/schemas/1.7.1/schema.json",
        "organizeImports": {
                "enabled": true
        },
        "linter": {
                "enabled": true,
                "rules": {
                        "recommended": true
                }
        }
}
❯ cat a.json
{
  "a": """
}
❯ cat hello.json
{
  "hello": "world",
  """
  "asdf": "zxcv",
}

a.json gives me 5 errors and doesn't panic:

❯ bunx biome check a.json
a.json:2:10 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Missing closing quote
  
    1 │ {
  > 2 │   "a": """
      │          ^
    3 │ }
    4 │ 
  
  ℹ line breaks here
  
    1 │ {
  > 2 │   "a": """
      │           
  > 3 │ }
      │ 
    4 │ 
  

a.json:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ expected `:` but instead found `}`
  
    1 │ {
    2 │   "a": """
  > 3 │ }
      │ ^
    4 │ 
  
  ℹ Remove }
  

a.json:2:10 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Missing closing quote
  
    1 │ {
  > 2 │   "a": """
      │          ^
    3 │ }
    4 │ 
  
  ℹ line breaks here
  
    1 │ {
  > 2 │   "a": """
      │           
  > 3 │ }
      │ 
    4 │ 
  

a.json:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ expected `:` but instead found `}`
  
    1 │ {
    2 │   "a": """
  > 3 │ }
      │ ^
    4 │ 
  
  ℹ Remove }
  

a.json format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Code formatting aborted due to parsing errors. To format code with errors, enable the 'formatter.formatWithErrors' option.
  

Checked 1 file in 440µs. No fixes needed.
Found 5 errors.
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Some errors were emitted while running checks.
  

hello.json bails after the first error:

❯ bunx biome check hello.json
hello.json:3:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Missing closing quote
  
    1 │ {
    2 │   "hello": "world",
  > 3 │   """
      │     ^
    4 │   "asdf": "zxcv",
    5 │ }
  
  ℹ line breaks here
  
    1 │ {
    2 │   "hello": "world",
  > 3 │   """
      │      
  > 4 │   "asdf": "zxcv",
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_text_size/src/range.rs:50:9
Thread Name: main
Message: assertion failed: start <= end

@redbmk
Copy link
Author

redbmk commented Apr 26, 2024

It looks like instead of three double-quotes, I can also do any of these:

""'
"'
'

I'm not quite seeing a pattern but I've found a few other simple test cases that cause it to bail:

{
  "
  '
}
{"hello": "world"
  '
  "}
{"
  '}

whereas these will work fine (reporting a handful of legit errors)

{
  ""'
}
{"hello": "world"
  '
}
{"hello": "world"
  '
"}
{"
'}

@Sec-ant
Copy link
Member

Sec-ant commented Apr 26, 2024

but I don't actually see a panic for the one reported in that issue.

Oh yes that is expected. you'll need to enable nursery rules to trigger the panic in that issue. In stable releases nursery rules are disabled by default and one has to set it explicitly in the settings to enable them.

I just tried creating a new config using bunx @biomejs/biome init and get the same error,

So this one is different, because this seems to be triggered by analyzing the keys instead of the values. But I guess it is still related to how we handle unterminated string literals.

Apart from #2357, another similar issue reported is #2410.

And thank you for providing the fail cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Parser Area: parser L-JSON Language: JSON and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants