twpayne / chezmoi

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

run time bug when `chezmoi doctor` invoked #3800

Closed yaaama closed 5 months ago

yaaama commented 5 months ago

Describe the bug

I used chezmoi doctor and it gives me a stack trace.

To reproduce

chezmoi doctor in the command line

Expected behavior

A clear and concise description of what you expected to happen.

Output of command with the --verbose flag

$ chezmoi --verbose doctor
panic: runtime error: slice bounds out of range [1:0]

goroutine 1 [running]:
github.com/twpayne/chezmoi/v2/internal/cmd.parseCommand({0xc000014157, 0x2}, {0x0, 0x0, 0x0})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/config.go:2872 +0x32e
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).editor(0xc00004c10e?, {0x0, 0x0, 0x0?})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/config.go:1212 +0x270
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).runDoctorCmd(0xc00001a008, 0xc0007a98a8?, {0x0?, 0x0?, 0x0?})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/doctorcmd.go:172 +0xe5
github.com/spf13/cobra.(*Command).execute(0xc00057d508, {0xc000388d90, 0x1, 0x1})
    /build/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc0003ec308)
    /build/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
    /build/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).execute(0xc0007a9de8?, {0xc000040310, 0x2, 0x2})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/config.go:1228 +0x78
github.com/twpayne/chezmoi/v2/internal/cmd.runMain({{0x566c01b52684, 0x6}, {0x0, 0x0}, {0x566c01b53700, 0x14}, {0x0, 0x0}}, {0xc000040310, 0x2, ...})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/cmd.go:270 +0x25c
github.com/twpayne/chezmoi/v2/internal/cmd.Main({{0x566c01b52684, 0x6}, {0x0, 0x0}, {0x566c01b53700, 0x14}, {0x0, 0x0}}, {0xc000040310, 0x2, ...})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/cmd.go:106 +0xa5
main.main()
    /build/chezmoi/src/chezmoi-2.48.2/main.go:24 +0xfb

Output of chezmoi doctor

The stack trace

$ chezmoi doctor
panic: runtime error: slice bounds out of range [1:0]

goroutine 1 [running]:
github.com/twpayne/chezmoi/v2/internal/cmd.parseCommand({0xc000014157, 0x2}, {0x0, 0x0, 0x0})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/config.go:2872 +0x32e
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).editor(0xc00004c10e?, {0x0, 0x0, 0x0?})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/config.go:1212 +0x270
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).runDoctorCmd(0xc0003ea008, 0xc0008218a8?, {0x0?, 0x0?, 0x0?})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/doctorcmd.go:172 +0xe5
github.com/spf13/cobra.(*Command).execute(0xc0007f9508, {0x642aa35115a0, 0x0, 0x0})
    /build/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc000512008)
    /build/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
    /build/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).execute(0xc000821de8?, {0xc000040050, 0x1, 0x1})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/config.go:1228 +0x78
github.com/twpayne/chezmoi/v2/internal/cmd.runMain({{0x642aa27c8684, 0x6}, {0x0, 0x0}, {0x642aa27c9700, 0x14}, {0x0, 0x0}}, {0xc000040050, 0x1, ...})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/cmd.go:270 +0x25c
github.com/twpayne/chezmoi/v2/internal/cmd.Main({{0x642aa27c8684, 0x6}, {0x0, 0x0}, {0x642aa27c9700, 0x14}, {0x0, 0x0}}, {0xc000040050, 0x1, ...})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/cmd.go:106 +0xa5
main.main()
    /build/chezmoi/src/chezmoi-2.48.2/main.go:24 +0xfb

Extra details

I adjusted my configuration for chezmoi stored in .config/chezmoi/chezmoi.toml, then it caused the specified issue

I also get the following warnings about the config template being edited or something:

$ cm diff
chezmoi: warning: config file template has changed, run chezmoi init to regenerate config file
$ chezmoi init
$ chezmoi doctor
panic: runtime error: slice bounds out of range [1:0]

goroutine 1 [running]:
github.com/twpayne/chezmoi/v2/internal/cmd.parseCommand({0xc000014157, 0x2}, {0x0, 0x0, 0x0})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/config.go:2872 +0x32e
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).editor(0xc00004c10e?, {0x0, 0x0, 0x0?})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/config.go:1212 +0x270
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).runDoctorCmd(0xc000557008, 0xc0007b98a8?, {0x0?, 0x0?, 0x0?})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/doctorcmd.go:172 +0xe5
github.com/spf13/cobra.(*Command).execute(0xc0007f7508, {0x58108b92a5a0, 0x0, 0x0})
    /build/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc000538008)
    /build/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
    /build/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).execute(0xc0007b9de8?, {0xc000132010, 0x1, 0x1})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/config.go:1228 +0x78
github.com/twpayne/chezmoi/v2/internal/cmd.runMain({{0x58108abe1684, 0x6}, {0x0, 0x0}, {0x58108abe2700, 0x14}, {0x0, 0x0}}, {0xc000132010, 0x1, ...})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/cmd.go:270 +0x25c
github.com/twpayne/chezmoi/v2/internal/cmd.Main({{0x58108abe1684, 0x6}, {0x0, 0x0}, {0x58108abe2700, 0x14}, {0x0, 0x0}}, {0xc000132010, 0x1, ...})
    /build/chezmoi/src/chezmoi-2.48.2/internal/cmd/cmd.go:106 +0xa5
main.main()
    /build/chezmoi/src/chezmoi-2.48.2/main.go:24 +0xfb
twpayne commented 5 months ago

What is the contents of your configuration file?

yaaama commented 5 months ago

Hope this helps

encryption = "gpg"
pager = "bat"
[data]
email = "xxxxx@xxxxxxxxxx"
name = "xxxx"
[diff]
# command = "diff-so-fancy"
pager = "diff-so-fancy"
# pager = "bat"
[edit]
# adds changes upon save
watch = false
# apply changes after exiting editor
apply = false
[gpg]
recipients = ["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
args = ["--quiet"]
[completion]
custom = true
[git]
# autoPush = true
# autoAdd = true
# autoCommit = true
twpayne commented 5 months ago

Thanks, what the values of your $EDITOR and $VISUAL environment variables?

yaaama commented 5 months ago

currently they are both empty (I'm messing around with my zshrc)

twpayne commented 5 months ago

Thanks for reporting this. I'm not able to reproduce the problem, but #3801 should fix it. Would you be able to test this?

yaaama commented 5 months ago

Thanks for reporting this. I'm not able to reproduce the problem, but #3801 should fix it. Would you be able to test this?

It is fixed! Thank you for the speedy replies and support 😄