twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.85k stars 477 forks source link

Reading IPv6 address from chezmoi prompt #2571

Closed 5u623l20 closed 1 year ago

5u623l20 commented 1 year ago

Describe the bug

I am trying to prompt the user for an IPv6 address and save it as part of the configuration using this file: https://github.com/bounce-commerce/dotfiles/blob/main/home/.chezmoi.toml.tmpl

However when I am trying to input the IPv6 address it ends up with an error:

chezmoi: template: chezmoi.toml:19:27: executing "chezmoi.toml" at <.>: wrong type for value; expected string; got map[string]interface {}

To reproduce

If we try to input: 2001:db8::1 for any string prompts it ends up like this.

Expected behavior

It should accept it as string with quotes

Output of command with the --verbose flag

$ chezmoi --verbose init
IPv6 address of primary interface 2001:db8::1
chezmoi: template: chezmoi.toml:19:27: executing "chezmoi.toml" at <.>: wrong type for value; expected string; got map[string]interface {}

Output of chezmoi doctor

$ chezmoi doctor
RESULT    CHECK                MESSAGE
ok        version              v2.27.1, commit b6039e787dfffe970fec4f9165ec9ebe1b3ceaa6, built at 2022-11-13T20:30:23Z, built by goreleaser
ok        latest-version       v2.27.1
ok        os-arch              freebsd/amd64 (FreeBSD 13.1-RELEASE-p3)
ok        uname                FreeBSD monitoring.bounce-commerce.de 13.1-RELEASE-p3 FreeBSD 13.1-RELEASE-p3 GENERIC amd64
ok        go-version           go1.19.3 (gc)
ok        executable           ~/bin/chezmoi
ok        upgrade-method       replace-executable
ok        config-file          no config file found
ok        source-dir           ~/.local/share/chezmoi is a git working tree (clean)
ok        suspicious-entries   no suspicious entries
ok        working-tree         ~/.local/share/chezmoi is a git working tree (clean)
ok        dest-dir             ~ is a directory
warning   umask                077
ok        cd-command           found /bin/csh
ok        cd-args              /bin/csh
info      diff-command         not set
ok        edit-command         found /usr/local/bin/vim
ok        edit-args            /usr/local/bin/vim
ok        git-command          found /usr/local/bin/git, version 2.38.1
ok        merge-command        found /usr/local/bin/vimdiff
ok        shell-command        found /bin/csh
ok        shell-args           /bin/csh
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

I think the : in colon in IPv6 addresses are somehow messing up the writing of the toml configs.

twpayne commented 1 year ago

The error is at line 19 in your config file template. You're calling promptBool but this should be promptBoolOnce.

5u623l20 commented 1 year ago

Thanks. What is the easier way of debugging such mistakes?

twpayne commented 1 year ago

The error message contains the filename, line number, and column of the error.

As general advice, if your suspected cause is suspiciously specific (why would chezmoi's promptStringOnce function behave differently for IPv6 addresses versus all other inputs?) then it's probably something else, and you should at least comment out the line you believe is causing the problem to verify that the error goes away when you remove the line.