This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
Backport of config/funcs: template functions to return valid ArgError values into release/0.4.x #1688
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.
Backport
This PR is auto-generated from #1679 to be assessed for backporting due to the inclusion of the label backport/0.4.x.
The below text is copied from the body of the original PR.
The template functions are all defined with a variadic parameter to collect zero or more
vars
maps, but that means we need to be careful to handle the case where there are novars
maps at all.This code seems to have originally been derived from Terraform's
templatefile
which has a non-variadic `vars, and so Terraform was correct to assume that argument 1 would always be present. Since Waypoint's version allows omitting it, we'll handle that situation by putting the "blame" on the template argument instead, to suggest that it's invalid to refer to any variables inside a template call that doesn't have any variables.The previous incorrect result was originally a panic due to violating the contract HCL expects for
function.ArgError
, although hashicorp/hcl#472 addressed that by just returning a less-specific error message in that case. This fix therefore boils down to just highlighting a more specific part of the input in the error message HCL will ultimately return.This originally arose in #1675. With this change, the input from that issue should return the new error message I added here and the error message should identify the
"${path.app}/job.hcl.tpl"
argument specifically as the expression that caused the error.