Skip to content
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

Merged
merged 1 commit into from
Dec 17, 2020
Merged

Conversation

pselle
Copy link
Contributor

@pselle pselle commented Dec 15, 2020

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.

@pselle pselle requested a review from a team December 15, 2020 21:09
hclsyntax/expression.go Outdated Show resolved Hide resolved
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.
@pselle pselle merged commit baa494e into hcl2 Dec 17, 2020
@pselle pselle deleted the pselle/marked-keys branch December 17, 2020 15:33
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Marked value as key",
Detail: "Can't use a marked value as a key.",
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants