-
-
Notifications
You must be signed in to change notification settings - Fork 624
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
Template function breaks the "requires" feature #1950
Comments
Hello version: 3
tasks:
default:
cmd: |
{{range .MY_VAR | splitList " " }}
{{end}} The above still results in an error. Your template seems incorrect, and I'm not sure what you're trying to achieve. cmd: '{{range .MY_VAR}}{{range splitList . " "}}{{.}}{{end}}{{end}}' |
Hi vmaerten. The use case is simple. Set MY_VAR to a space delimited list of words (by the task runner person), then iterate on them. But MY_VAR is REQUIRED! In other words, the task fails late, not early. And it is an incorrect behavior from the user's standpoint. Early failure is when we immediately see the missing required variable, and not even attempt to resolve the template (as it depends on the variable, hence the template error. It is NOT a syntax error, it is fully valid templating syntax). Here is an example:
To call the task, the user gives something like this: And the result is:
And of course, since we are talking about real world use cases, the template error should rightfully happen when the user provides an incorrect variable. But here, the user explicitly wants to tell Task to ensure the existence of a variable, becasue it is a dependency of the template. |
Thank you for the explanation! I apologize for not fully understanding your issue initially. You're absolutely right—in your case, which is valid, the message should be: Until this is addressed, you can use the following workaround by defining a default value: version: 3
tasks:
default:
requires:
vars: [MY_VAR]
cmd: |
{{range (default "" .MY_VAR) | splitList " " }}
echo {{.}}
{{end}} |
This could be the exact same, or similar issue as #1557, but there is no reproduction happening there, so I decided to make a new issue, because I found a way to reproduce the "requires" breakage. The required variable is not enforced in the below example.
Expected: "task: Task "default" cancelled because it is missing required variables: MY_VAR"
Result: "template: :1:28: executing "" at <" ">: invalid value; expected string"
Taskfile:
When not using the template function, the required variable feature works as expected.
Result: "task: Task "default" cancelled because it is missing required variables: MY_VAR"
The text was updated successfully, but these errors were encountered: