Open hmarko opened 1 year ago
This beheviour happens on words like: on, off, true, false used as yaml keys.
@hmarko thanks for reporting this!
Panicking is not great đ˘
Treating on
as a boolean is YAML as per spec. Unless quoted a string matching y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF
is treated as a boolean. See this example on the playground.
To be able to use the key on
- as shown in your example - quote it:
#@data/values
---
general:
notifications:
recipients:
- admin@test.com
"on":
- any
Thank you ! I think it worth taking care of it to prevent nasty panics from happening. tools like ytt should template this anyway (what will happen if I want to change true to false as per the yaml spec using ytt ?)
Thank you ! I think it worth taking care of it to prevent nasty panics from happening.
I agree, the panic isn't right. However, I think the right behavior according to spec is to treat your data values like so:
#@data/values
---
general:
notifications:
recipients:
- admin@test.com
true: #! note the boolean
- any
tools like ytt should template this anyway (what will happen if I want to change true to false as per the yaml spec using ytt ?)
I am not sure I follow you here. Can you expound and maybe provide an example?
Ok, I think I got it now :-) My YAML uses the on: boolean as both key and value in the hierarchy. I cannot really use it as a key according to the spec.
@hmarko it's not you, this was a "good intention, bad impact" idea that we actually had intended to "fix". But that work has not yet been prioritized by the maintainers. See #407.
What remains, tho, is the better handling. As @mamachanko noted above: panics are suitable for when something goes terribly wrong internally. When the problem arises directly from our inputs, we should error out gracefully with a helpful + actionable message. đđť
I'm going to adjust this issue to capture that scope.
When a non-string value has been provided for an key in a struct,
ytt
should report an errorrather than panic (see below).
đđť original report đđť
when using
on
as a key in yaml (see below example) ytt panics. changing it to anything else solves it (just change the on: to on1: for example)config.yaml:
data.yaml:
ytt panics with the following stack trace:
Environment: ytt version 0.43.0 CentOS Linux release 7.8.2003 (Core)