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

hclsyntax: address multiple issues with sequences (...) #386

Merged
merged 3 commits into from
Jun 3, 2020

Conversation

mildwonkey
Copy link
Contributor

@mildwonkey mildwonkey commented Jun 3, 2020

Update: I ended up tackling two adjacent bugs at once.


Previously functions such as concat() would result in a panic if there
was a null element and a sequence, as in the included test. This PR adds
a check if the error index is outside of the range of arguments and
crafts an error that references the entire function instead of the null
argument.

Tested locally to confirm that this fixes a reported terraform panic:
Screen Shot 2020-06-03 at 9 13 08 AM

Previously functions such as concat() would result in a panic if there
was a null element and a sequence, as in the included test. This PR adds
a check if the error index is outside of the range of arguments and
crafts an error that references the entire function instead of the null
argument.
@mildwonkey mildwonkey requested a review from a team June 3, 2020 13:17
@mildwonkey
Copy link
Contributor Author

mildwonkey commented Jun 3, 2020

hashicorp/terraform#24910 is the reference for the second commit, which addresses the following error with ... and unknowns:

Previous error (as shown by the test added in this comment):
expression_test.go:1561: - :1,8-23: Invalid expanding argument value; The expanding argument (indicated by ...) must be of a tuple, list, or set type.

New result: no errors, returns cty.DynamicVal

@@ -260,6 +260,8 @@ func (e *FunctionCallExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
}

switch {
case expandVal.Type().Equals(cty.DynamicPseudoType):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If passing null as the first argument isn't valid, we should have the same null check here as below. Otherwise we have a known value turning into an unknown value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fixed!

@mildwonkey mildwonkey changed the title hclsyntax: do not panic when encountering a null + sequence (...) hclsyntax: address multiple issues with sequences (...) Jun 3, 2020
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.

None yet

2 participants