-
Notifications
You must be signed in to change notification settings - Fork 597
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
Error if attempting to use marked value as key #434
Conversation
When evaluating an HCL expression attempting to use a marked value as an object key, return an error rather than falling through to the cty panic. The error style mimics similar errors in the area.
df4dfbc
to
c227eb4
Compare
diags = append(diags, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "Marked value as key", | ||
Detail: "Can't use a marked value as a key.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this is a late-arriving review given that this is already merged and queued for release, but... it feels weird to me to talk about "marked values" in user-facing error messages, because this idea of marks has so far been just an implementation detail.
Based on how marks behave down at the cty
layer I would've expected any marks from the keys to be silently transferred to be marks on the map itself, rather than this producing an error. 🤔
I think if we were to decide to change this later then it wouldn't be considered a breaking change because it would turn something that was formerly an error into something that is now a "more correct" success (though of course that's a matter of opinion), so I think it'd be okay to go ahead with this in the meantime, but I'd like to talk this out a little and see what the tradeoffs would be for the alternative behavior I proposed above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've put this on my backlog to re-visit -- thanks for sharing this feedback, I also don't like making errors in HCL mention marks (also because they have to disclose that there are marks in a general sense, whereas in Terraform, they can be specific to what kind of marks are present, which currently only includes sensitive
).
The idea of preserving the marks and then marking the whole object mimics other behavior we have, and I appreciate the input that we won't have to consider it a breaking change.
When evaluating an HCL expression attempting to use a marked value as an object key, return an error rather than falling through to the cty panic.
The error text mimics similar errors in the area, but could be more similar to #433 (or changed in either location) if preferred.