When accessing chezmoi data in a template file using the default (sprig) method, I get an error if that data is not present in the chezmoi.toml config file yet (i.e. first init call):
chezmoi: template: chezmoi.toml:1:54: executing "chezmoi.toml" at <.testValue>: map has no entry for key "testValue"
This seems to be a regression from 2.25.0 -> 2.26.0 (also affecting 2.27.0 and latest 2.28.0).
Run chezmoi init without an existing config file ~/.config/chezmoi/chezmoi.toml.
Expected behavior
I expect the init function to use a default value whenever a variable is empty/null, or in this case, the map has no entry for the provided key value "testValue".
This has been working properly in previous versions, including 2.25.0:
$ chezmoi init
Test value? string, default default_test_value
I have previously used this workaround to always have the current config values as default values whenever I call the init function again (i.e. "keep current value").
This is required as I store many variables that are based on the actual hardware used, i.e. ~8 devices with ~30 config variables each that might differ from device to device.
Output of command with the --verbose flag
$ chezmoi --verbose init
chezmoi: template: chezmoi.toml:1:54: executing "chezmoi.toml" at <.testValue>: map has no entry for key "testValue"
Output of chezmoi doctor
```console
RESULT CHECK MESSAGE
ok version v2.28.0, commit 8e9ed2eee04b708b4d7531863e47b5c5a876050f, built at 2022-12-18T18:40:56Z, built by goreleaser
ok latest-version v2.28.0
ok os-arch linux/arm (LibreELEC 10.0.3)
ok uname Linux kodi-guestroom 5.10.110 #1 SMP Sat Oct 15 00:13:37 UTC 2022 armv7l GNU/Linux
ok go-version go1.19.4 (gc)
ok executable ~/bin/chezmoi
ok upgrade-method replace-executable
ok config-file no config file found
error source-dir ~/.local/share/chezmoi is a git working tree (error)
warning suspicious-entries ~/.local/share/chezmoi/.chezmoi.toml.tmpl_bak
error working-tree ~/.local/share/chezmoi is a git working tree (error)
ok dest-dir ~ is a directory
ok umask 022
ok cd-command found /bin/sh
ok cd-args /bin/sh
info diff-command not set
ok edit-command found /usr/bin/nano
ok edit-args /usr/bin/nano
warning git-command git not found in $PATH
warning merge-command vimdiff not found in $PATH
ok shell-command found /bin/sh
ok shell-args /bin/sh
info age-command age not found in $PATH
info gpg-command gpg not found in $PATH
info pinentry-command not set
info 1password-command op not found in $PATH
info bitwarden-command bw not found in $PATH
info gopass-command gopass not found in $PATH
info keepassxc-command keepassxc-cli not found in $PATH
info keepassxc-db not set
info keeper-command keeper not found in $PATH
info lastpass-command lpass not found in $PATH
info pass-command pass not found in $PATH
info passhole-command ph not found in $PATH
info vault-command vault not found in $PATH
info secret-command not set
```
Additional context
This also happens if I try to wrap the non-existent data in a ternary (sprig) method. Using the ternary method, I would assume that only the true xor false branch gets accessed. But whenever there is a access to not-yet-initialized .testValue, this method also fails with the above error.
This problem also occurs on other systems, e.g. linux/amd64 (Arch Linux).
Not fully tested yet:It seems that using the default method in other templates (anything but .chezmoi.toml.tmpl) generates this error even for versions prior to 2.26.0.
Describe the bug
When accessing chezmoi data in a template file using the default (sprig) method, I get an error if that data is not present in the
chezmoi.toml
config file yet (i.e. first init call):This seems to be a regression from 2.25.0 -> 2.26.0 (also affecting 2.27.0 and latest 2.28.0).
To reproduce
Create a file
.chezmoi.toml.tmpl
:Run
chezmoi init
without an existing config file~/.config/chezmoi/chezmoi.toml
.Expected behavior
I expect the
init
function to use a default value whenever a variable is empty/null, or in this case, the map has no entry for the provided key value "testValue".This has been working properly in previous versions, including 2.25.0:
I have previously used this workaround to always have the current config values as default values whenever I call the init function again (i.e. "keep current value").
This is required as I store many variables that are based on the actual hardware used, i.e. ~8 devices with ~30 config variables each that might differ from device to device.
Output of command with the
--verbose
flagOutput of
chezmoi doctor
Additional context
.testValue
, this method also fails with the above error.linux/amd64 (Arch Linux)
..chezmoi.toml.tmpl
) generates this error even for versions prior to 2.26.0.