hclsyntax: Special error messages for EOF in certain contexts #492
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For parts of the input that are delimited by start and end tokens, our typical pattern is to keep scanning for items until we reach the end token, or to generate an error if we encounter a token that isn't valid.
In some common examples of that we'll now treat
TokenEOF
as special and report a different message about the element being unclosed, because it seems common in practice for folks to leave off closing delimiters and then be confused about HCL reporting a parse error at the end of the file. Instead, we'll now report the error from the perspective of the opening token(s) and describe that construct as "unclosed", because the EOF range is generally less useful than any range that actually contains some relevant characters.This is not totally comprehensive for all cases, but covers some situations that I've seen folks ask about, and some others that were similar enough to those that it was easy to modify them in the same ways.
This does actually change one of the error ranges constrained by the specification test suite, but in practice we're not actually using that test suite to represent the "specification" for HCL, so it's better to change the hypothetical specification to call for a better error reporting behavior than to retain the old behavior just because we happened to encoded in the (unfinished) test suite.
Here's how one example of these new error messages looks when integrated into Terraform: