hashicorp / hashicorp/consul-template
Unhelpful error when passing `nomadVar` to a string func
- Dominant language
- Go
- Stars
- 4.8k
- Forks
- 801
- Avg merge
- 4h 5m
- Merged PRs (30d)
- 6
Description
So this report is partially to report a possibility of improving documentation as well as a bug in error messages.
The documentation shows that you can template a variable as if it was a string using the following syntax:
```
{{ with nomadVar "nomad/jobs/blocky" -}}
{{ .whitelists_ads }}
{{- end }}
```
And that works just fine, however the value is not a string. It is instead a `NomadVarItem`. The documentation does mention that it returns this type, so there is no bug there.
As I'm migrating from Consul to Nomad Variables, I was expecting a similar format and tried to indent this value using the configuration shown below. At that point it returns an error that is very difficult to read. Some sanitization gone wrong I think. If the error was more readable I'd probably have looked up the struct and then fixed the issue by adding `.Value` to the end, but it was not even fully expressed within Nomad due to being truncated.
Finally, it may be worth mentioning that passing the value as a string to other functions will require adding `.Value` to the end of the field for those that are familiar with using Consul KV.
### Consul Template version
`pinned-for-nomad-1.4.1`
### Configuration
```liquid
{{ with nomadVar "nomad/jobs/blocky" -}}
{{ .whitelists_ads | indent 6 }}
{{- end }}
```
```liquid
Path "nomad/jobs/blocky"
Items: {
whitelist_ads = "somevalue"
}
```
### Command
```shell
consul-template -once -dry --template ./core/blocky/config.yml
```
### Debug output
Provide a link to a GitHub Gist containing the complete debug
output by running with `-log-level=trace`.
### Expected behavior
Render the value indented 6 spaces.
### Actual behavior
A very difficult to read error
```
2022-11-22T10:50:56.018-0800 [ERR] (cli) ./core/blocky/config.yml: execute: [redacted]t[redacted]e[redacted]m[redacted]p[redacted]l[redacted]a[redacted]t[redacted]e[redacted]:[redacted]
[redacted]:[redacted]7[redacted]9[redacted]:[redacted]6[redacted]1[redacted]:[redacted] [redacted]e[redacted]x[redacted]e[redacted]c[redacted]u[redacted]t[redacted]i[redacted]n[redacted]
g[redacted] [redacted]"[redacted]"[redacted] [redacted]a[redacted]t[redacted] [redacted]<[redacted]4[redacted]>[redacted]:[redacted] [redacted]w[redacted]r[redacted]o[redacted]n[redacted
]g[redacted] [redacted]t[redacted]y[redacted]p[redacted]e[redacted] [redacted]f[redacted]o[redacted]r[redacted] [redacted]v[redacted]a[redacted]l[redacted]u[redacted]e[redacted];[redacte
d] [redacted]e[redacted]x[redacted]p[redacted]e[redacted]c[redacted]t[redacted]e[redacted]d[redacted] [redacted]s[redacted]t[redacted]r[redacted]i[redacted]n[redacted]g[redacted];[redact
ed] [redacted]g[redacted]o[redacted]t[redacted] [redacted]d[redacted]e[redacted]p[redacted]e[redacted]n[redacted]d[redacted]e[redacted]n[redacted]c[redacted]y[redacted].[redacted]N[redac
ted]o[redacted]m[redacted]a[redacted]d[redacted]V[redacted]a[redacted]r[redacted]I[redacted]t[redacted]e[redacted]m[redacted]
```
### Steps to reproduce
1. Pipe the value of any `nomadVar` to a string function
2. Try to make sense of error
Contributor guide
Research direction
Start by reproducing the issue with the shown template, Nomad variable data, and `consul-template -once -dry --template ./core/blocky/config.yml`. Trace how `nomadVar` reaches the `indent` string function and how the resulting type error is rendered. Done means the error is readable and the documentation explains when `.Value` is required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, documentation
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100