hclwrite: body.SetAttribute* return new attribute - #806
Open
bbasata wants to merge 5 commits into
Open
Conversation
This change updates Body.SetAttribute* to return the new attribute rather than return nil. This matches the intent in the documentation comments that indicate: The return value is the attribute that was either modified in-place or created.
bbasata
marked this pull request as ready for review
June 15, 2026 22:04
Collaborator
Author
|
TIL: #613 |
Collaborator
Author
|
Tests have been ... driven! These fail on |
mildwonkey
reviewed
Jul 29, 2026
| // | ||
| // If there are no diagnostics, returns the value. | ||
| // If there are diagnostics, fails the test. | ||
| func must[E any](t *testing.T) func(value E, diags hcl.Diagnostics) E { |
Contributor
There was a problem hiding this comment.
This is the nittiest of nitpicks I can pick (and I'm genuinely sorry for it), but what do you think about naming this something different? testFn instead of must, maybe?
We use "must" in terraform test fixtures to mean "this will panic if it fails" and "test" for test helpers, and while this obviously isn't terraform, consistency simplifies reviewing.
Collaborator
Author
There was a problem hiding this comment.
test + must -> trust? :)
Collaborator
Author
There was a problem hiding this comment.
Yes, I typically want a must function to panic. In this case, I extracted an existing "do something, and t.Fatal on diagnostics" pattern from this file.
jbardin
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This change updates
hclwrite.Body.SetAttribute*to return the new attribute rather than returnnil.This matches the intent in the documentation comments that indicate:
An available workaround:
Open question: I'm considering whether to check the return value of
Body.SetAttribute*inhclwrite/ast_body_test.go.