hclsyntax: Hint about possible unescaped ${ for other languages #462
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.
It's a common error to accidentally include a
${
intended to be processed as part of another language after HCL processing, such as a shell script or an AWS IAM policy document.Exactly what sort of error will appear in that case unfortunately depends on the syntax for that other language, but a lot of them happen to end up in the codepath where we report the "Extra characters after interpolation expression" diagnostic message. For that reason, this extends that error message with an additional hint about escaping.
I've also included a special case for colons because they happen to arise in both Bash and AWS IAM interpolation syntax, albeit with different meanings. The specialized error message doesn't really say anything the generic one doesn't, but it does explicitly identify the colon as being the problem, which I hope will be helpful in thinking about what parts of this are being parsed in which layer.
Because this message is coming from HCL and HCL doesn't typically assume anything about the application where it's being used, the hint message is pretty generic and focuses only on the hint about the escaping syntax, in the hope that this will be hint enough to prompt the user to think about what they are currently working on and realize how to respond to this error.
The existing test cases in HCL typically only test that particular input fails, not what messages are returned when doing so, and so since this is effectively just changing the text of an existing error message it's not covered by any new tests. However, I've included examples of the new error messages below, which I viewed by exercising this codepath using the
hcldec
command line tool:This is a compromise aimed at the problem discussed in #460.