hcldec: Improved context for expression diagnostics #329
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.
The two cases where we decode attribute values should include the expression and
EvalContext
in any diagnostics they generate so that the calling application can give hints about the types and values of variables that are used within the expression.This also includes some adjustments to the returned source ranges so that both cases are consistent with one another and so that both indicate the entire expression as the
Subject
and include the attribute name in theContext
. Including the whole expression in the range ensures that when there's a problem inside a tuple or object constructor, for example, we'll show the line containing the problem and not just the opening[
or{
symbol.We don't have any specific tests in HCL for the metadata on diagnostics so in order to test this I linked it into Terraform and did the mistake that most commonly causes this error in Terraform usage:
Before this change, the message looked like this instead: