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

[BUG] Out of Bounds error while diffing two Terraform files #481

Closed
bgshacklett opened this issue Nov 16, 2022 · 4 comments
Closed

[BUG] Out of Bounds error while diffing two Terraform files #481

bgshacklett opened this issue Nov 16, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@bgshacklett
Copy link

Describe the bug
Out of Bounds error while diffing two Terraform files

To Reproduce
Steps to reproduce the behavior:

  1. Configure diffsitter to treat .tf files as hcl.
{
  "grammar": {
    "file-associations": {
      "tf": "hcl"
    }
  }
}
  1. Create two Terraform files:
cat <<EOF > test-a.tf
locals {
}
EOF
cat <<EOF > test-b.tf
locals {
  foo = "foo"
}
EOF
  1. Diff the two files:
❯ diffsitter test-a.tf test-b.tf
  1. An error is generated:
thread 'main' panicked at 'byte index 14 is out of bounds of `  foo = "foo"`', src/formatting.rs:440:43

Expected behavior
The diff should be printed without any error.

Log output/screenshots

❯ RUST_BACKTRACE=full diffsitter --debug test-a.tf test-b.tf
 2022-11-16T20:11:09.402Z DEBUG diffsitter > Checking if test-a.tf can be parsed
 2022-11-16T20:11:09.402Z INFO  diffsitter::parse > Deduced language "hcl" from extension "tf" provided from user mappings
 2022-11-16T20:11:09.402Z INFO  diffsitter::parse > Using tree-sitter parser for language hcl
 2022-11-16T20:11:09.402Z INFO  diffsitter::parse > Succeeded loading grammar for hcl
 2022-11-16T20:11:09.402Z DEBUG diffsitter        > Checking if test-b.tf can be parsed
 2022-11-16T20:11:09.402Z INFO  diffsitter::parse > Deduced language "hcl" from extension "tf" provided from user mappings
 2022-11-16T20:11:09.402Z INFO  diffsitter::parse > Using tree-sitter parser for language hcl
 2022-11-16T20:11:09.402Z INFO  diffsitter::parse > Succeeded loading grammar for hcl
 2022-11-16T20:11:09.402Z DEBUG diffsitter        > Extensions for both input files are supported
 2022-11-16T20:11:09.402Z DEBUG diffsitter        > Reading test-a.tf to string
 2022-11-16T20:11:09.402Z INFO  diffsitter        > Will deduce filetype from file extension
 2022-11-16T20:11:09.402Z INFO  diffsitter::parse > Deduced language "hcl" from extension "tf" provided from user mappings
 2022-11-16T20:11:09.402Z INFO  diffsitter::parse > Using tree-sitter parser for language hcl
 2022-11-16T20:11:09.402Z INFO  diffsitter::parse > Succeeded loading grammar for hcl
 2022-11-16T20:11:09.402Z DEBUG diffsitter::parse > Constructed parser
 2022-11-16T20:11:09.402Z DEBUG diffsitter::parse > Parsed AST
 2022-11-16T20:11:09.402Z INFO  TimerFinished     > parse::parse_file(), Elapsed=225.133µs
 2022-11-16T20:11:09.403Z DEBUG diffsitter        > Reading test-b.tf to string
 2022-11-16T20:11:09.403Z INFO  diffsitter        > Will deduce filetype from file extension
 2022-11-16T20:11:09.403Z INFO  diffsitter::parse > Deduced language "hcl" from extension "tf" provided from user mappings
 2022-11-16T20:11:09.403Z INFO  diffsitter::parse > Using tree-sitter parser for language hcl
 2022-11-16T20:11:09.403Z INFO  diffsitter::parse > Succeeded loading grammar for hcl
 2022-11-16T20:11:09.403Z DEBUG diffsitter::parse > Constructed parser
 2022-11-16T20:11:09.403Z DEBUG diffsitter::parse > Parsed AST
 2022-11-16T20:11:09.403Z INFO  TimerFinished     > parse::parse_file(), Elapsed=73.527µs
 2022-11-16T20:11:09.403Z INFO  TimerFinished     > ast::from_ts_tree(), Elapsed=18.268µs
 2022-11-16T20:11:09.403Z INFO  TimerFinished     > ast::process(), Elapsed=37.945µs
 2022-11-16T20:11:09.403Z INFO  TimerFinished     > ast::from_ts_tree(), Elapsed=3.375µs
 2022-11-16T20:11:09.403Z INFO  TimerFinished     > ast::process(), Elapsed=9.209µs
 2022-11-16T20:11:09.403Z INFO  TimerFinished     > diff::compute_edit_script(), Elapsed=4.517µs
 2022-11-16T20:11:09.403Z INFO  diffsitter::formatting > Detected terminal width: 104 columns
 2022-11-16T20:11:09.403Z INFO  diffsitter::formatting > Using stack style horizontal for title
 2022-11-16T20:11:09.403Z DEBUG diffsitter::formatting > Printing remaining old hunks
 2022-11-16T20:11:09.403Z DEBUG diffsitter::formatting > Printing remaining new hunks
 2022-11-16T20:11:09.403Z DEBUG diffsitter::formatting > Printing hunk (lines 1 - 1)
 2022-11-16T20:11:09.403Z DEBUG diffsitter::formatting > Title string has length of 3
 2022-11-16T20:11:09.403Z DEBUG diffsitter::formatting > Printing line 1
thread 'main' panicked at 'byte index 14 is out of bounds of `  foo = "foo"`', src/formatting.rs:440:43
stack backtrace:
   0:        0x10026b306 - __mh_execute_header
   1:        0x10021093b - __mh_execute_header
   2:        0x1002672e0 - __mh_execute_header
   3:        0x10026ebbb - __mh_execute_header
   4:        0x10026f428 - __mh_execute_header
   5:        0x10026ef24 - __mh_execute_header
   6:        0x10026ee99 - __mh_execute_header
   7:        0x10026ee55 - __mh_execute_header
   8:        0x10036da03 - __mh_execute_header
   9:        0x10036deec - __mh_execute_header
  10:        0x100185de8 - __mh_execute_header
  11:        0x10019468b - __mh_execute_header
  12:        0x1001a9096 - __mh_execute_header
  13:        0x1001ab227 - __mh_execute_header
  14:     0x7ff809791310 - <unknown>
 2022-11-16T20:11:09.404Z INFO  TimerFinished          > formatting::print(), Elapsed=727.907µs
test-a.tf -> test-b.tf
======================

1:
--
+   foo = "foo"%

Platform:
OS: macOS 13 (Ventura)

@bgshacklett bgshacklett added the bug Something isn't working label Nov 16, 2022
@bgshacklett
Copy link
Author

Possibly related to #468?

@afnanenayet
Copy link
Owner

Thanks for the report, this is an interesting little bug. The Go one appears to because I assumed that there would never be a node that's just a newline, unclear if this one is the same

@afnanenayet
Copy link
Owner

The bugfix for #468 is in the latest release. Could you let me know if this fixes your issue here?

@bgshacklett
Copy link
Author

It looks like that did it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants