terraform/internal/command/views/json
Martin Atkins 70bc432f85 command/views/json: Never generate invalid diagnostic snippet offsets
Because our snippet generator is trying to select whole lines to include
in the snippet, it has some edge cases for odd situations where the
relevant source range starts or ends directly at a newline, which were
previously causing this logic to return out-of-bounds offsets into the
code snippet string.

Although arguably it'd be better for the original diagnostics to report
more reasonable source ranges, it's better for us to report a
slightly-inaccurate snippet than to crash altogether, and so we'll extend
our existing range checks to check both bounds of the string and thus
avoid downstreams having to deal with out-of-bounds indices.

For completeness here I also added some similar logic to the
human-oriented diagnostic formatter, which consumes the result of the
JSON diagnostic builder. That's not really needed with the additional
checks in the JSON diagnostic builder, but it's nice to reinforce that
this code can't panic (in this way, at least) even if its input isn't
valid.
2021-06-28 13:42:28 -07:00
..
testdata/diagnostic command/views/json: Never generate invalid diagnostic snippet offsets 2021-06-28 13:42:28 -07:00
change.go Move plans/ to internal/plans/ 2021-05-17 14:09:07 -07:00
change_summary.go Move command/ to internal/command/ 2021-05-17 14:09:07 -07:00
diagnostic.go command/views/json: Never generate invalid diagnostic snippet offsets 2021-06-28 13:42:28 -07:00
diagnostic_test.go command/views/json: Never generate invalid diagnostic snippet offsets 2021-06-28 13:42:28 -07:00
hook.go Move plans/ to internal/plans/ 2021-05-17 14:09:07 -07:00
message_types.go command/views: Remove unused drift summary message 2021-05-25 15:54:57 -04:00
output.go Move states/ to internal/states/ 2021-05-17 14:09:07 -07:00
output_test.go update to use typed sensitive marks 2021-06-25 12:49:07 -04:00
resource_addr.go Move command/ to internal/command/ 2021-05-17 14:09:07 -07:00