twpayne / chezmoi

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

Windows panic: runtime error: invalid memory address or nil pointer dereference #2350

Closed riotrah closed 1 year ago

riotrah commented 1 year ago

Firstly, love chezmoi, been using it for like a year already on win, mac, ubuntu wsl, termux and even alpine (gitpod.io containers).

What exactly are you trying to do?

Describe in as much detail as possible.

On windows 11

  1. Many actions fail with a panic: runtime error: invalid memory address or nil pointer dereference error
    • Including (even with --keep-going)
      • status
      • apply
      • diff
      • merge-all
    • But not:
      • init
      • edit-*
      • add
      • git *
      • cd
      • execute-template
      • update
      • verify
  2. I've been trying to figure this out as much as possible to avoid burdening you, but after several weeks, I'm wondering what I'm doing wrong :/

Perhaps important context - for this windows machine alone, I use symlink mode

What have you tried so far ?

Describe what you have tried so far.

  1. Updated

  2. Purged

  3. Looked for potentially circular dependencies

  4. altered externals or removed them entirely

  5. Removed all scripts

  6. Rebuilt up local chezmoi config bit by bit

  7. Followed the verbose/debug trace up to its last ReadDir:

    2022-09-10T14:09:48-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/scripts/dot_vscode
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xc0000005 code=0x0 addr=0x40 pc=0x13acd1f]
  8. and tried to

    1. Delete/ignore/remove the files that were last
    2. Predict which files were next and delete/ignore/remove those

Where else have you checked for solutions?

Output of any commands you've tried with --verbose flag

```console $ chezmoi status -v -k --debug 2022-09-10T14:21:45-07:00 INF persistentPreRunRootE args=["C:\\ProgramData\\chocolatey\\lib\\chezmoi\\tools\\chezmoi.exe","status","-v","-k","--debug"] goVersion=go1.19 version={"builtBy":"goreleaser","commit":"64b9c1fa7346526c17d5073827fe055dc46f6c09","date":"2022-09-04T23:00:07Z","version":"2.22.1"} 2022-09-10T14:21:45-07:00 INF Stat component=system name=C:/Users/rayat/.config/chezmoi/chezmoistate.boltdb 2022-09-10T14:21:45-07:00 ERR Mkdir error="mkdir C:/Users/rayat/.config/chezmoi: Cannot create a file when that file already exists." component=system name=C:/Users/rayat/.config/chezmoi perm=511 2022-09-10T14:21:45-07:00 INF Stat component=system name=C:/Users/rayat/.config/chezmoi 2022-09-10T14:21:45-07:00 INF Stat component=system name=C:/Users/rayat/.local/share/chezmoi 2022-09-10T14:21:45-07:00 INF Stat component=system name=C:/Users/rayat/.local/share/chezmoi/.git 2022-09-10T14:21:45-07:00 ERR ReadFile error="open C:/Users/rayat/.local/share/chezmoi/.chezmoiversion: The system cannot find the file specified." component=system data= name=C:/Users/rayat/.local/share/chezmoi/.chezmoiversion size=0 2022-09-10T14:21:45-07:00 ERR ReadFile error="open C:/Users/rayat/.local/share/chezmoi/.chezmoiroot: The system cannot find the file specified." component=system data= name=C:/Users/rayat/.local/share/chezmoi/.chezmoiroot size=0 2022-09-10T14:21:45-07:00 INF Stat component=system name=C:/Users/rayat/.local/share/chezmoi 2022-09-10T14:21:45-07:00 INF Stat component=system name=C:/Users/rayat/.local/share/chezmoi 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi 2022-09-10T14:21:45-07:00 INF ReadFile component=system data="{{- $fontDir := \"\" }}\r\n{{- if eq .chezmoi.os \"darwin\" }}\r\n{{- ..." name=C:/Users/rayat/.local/share/chezmoi/.chezmoiexternal.toml size=1123 2022-09-10T14:21:45-07:00 INF ReadFile component=system data="# ignore windows paths\r\n{{- if ne .chezmoi.os \"windows\" }}\r\n\r\n*...." name=C:/Users/rayat/.local/share/chezmoi/.chezmoiignore size=638 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/.chezmoiscripts 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/AutoHotkey 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/AutoHotkey/Lib 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/AutoHotkey/Lib/dot_vscode 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/Modules 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/Modules/EspansoTexpandTools 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/Scripts 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/Scripts/InstalledScriptInfos 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/Scripts/completions 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/dot_vscode 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/code 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_config 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_config/broot 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_config/cheat 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_config/clj-kondo 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_config/lvim 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_lein 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_local 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_local/share 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_local/share/zsh-completions 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/scripts 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/scripts/dot_vscode 2022-09-10T14:21:45-07:00 ERR ReadFile error="open C:/Users/rayat/.local/share/chezmoi/.chezmoiroot: The system cannot find the file specified." component=system data= name=C:/Users/rayat/.local/share/chezmoi/.chezmoiroot size=0 2022-09-10T14:21:45-07:00 ERR ReadFile error="open C:/Users/rayat/.local/share/chezmoi/.chezmoi.json.tmpl: The system cannot find the file specified." component=system data= name=C:/Users/rayat/.local/share/chezmoi/.chezmoi.json.tmpl size=0 2022-09-10T14:21:45-07:00 INF ReadFile component=system data="{{- $amperity := false -}}\r\n{{- $personal := false -}}\r\n{{- if (..." name=C:/Users/rayat/.local/share/chezmoi/.chezmoi.toml.tmpl size=2326 2022-09-10T14:21:45-07:00 INF Get bucket=configState component=persistentState key=configState value="{\"configTemplateContentsSHA256\":\"98d9002d35792f66162957b04ccc6e6d3aabfbcf06db6b818f5eccd8496707a9\"}" 2022-09-10T14:21:45-07:00 ERR ReadFile error="open C:/Users/rayat/.local/share/chezmoi/.chezmoiversion: The system cannot find the file specified." component=system data= name=C:/Users/rayat/.local/share/chezmoi/.chezmoiversion size=0 2022-09-10T14:21:45-07:00 ERR ReadFile error="open C:/Users/rayat/.local/share/chezmoi/.chezmoiroot: The system cannot find the file specified." component=system data= name=C:/Users/rayat/.local/share/chezmoi/.chezmoiroot size=0 2022-09-10T14:21:45-07:00 INF Stat component=system name=C:/Users/rayat/.local/share/chezmoi 2022-09-10T14:21:45-07:00 INF Stat component=system name=C:/Users/rayat/.local/share/chezmoi 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi 2022-09-10T14:21:45-07:00 INF ReadFile component=system data="{{- $fontDir := \"\" }}\r\n{{- if eq .chezmoi.os \"darwin\" }}\r\n{{- ..." name=C:/Users/rayat/.local/share/chezmoi/.chezmoiexternal.toml size=1123 2022-09-10T14:21:45-07:00 INF ReadFile component=system data="# ignore windows paths\r\n{{- if ne .chezmoi.os \"windows\" }}\r\n\r\n*...." name=C:/Users/rayat/.local/share/chezmoi/.chezmoiignore size=638 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/.chezmoiscripts 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/AutoHotkey 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/AutoHotkey/Lib 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/AutoHotkey/Lib/dot_vscode 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/Modules 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/Modules/EspansoTexpandTools 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/Scripts 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/Scripts/InstalledScriptInfos 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/Scripts/completions 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/Documents/Powershell/dot_vscode 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/code 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_config 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_config/broot 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_config/cheat 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_config/clj-kondo 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_config/lvim 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_lein 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_local 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_local/share 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/dot_local/share/zsh-completions 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/scripts 2022-09-10T14:21:45-07:00 INF ReadDir component=system name=C:/Users/rayat/.local/share/chezmoi/scripts/dot_vscode panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x40 pc=0x13acd1f] goroutine 1 [running]: github.com/twpayne/chezmoi/v2/pkg/chezmoi.(*SourceState).Apply(0xc0000dfce0, {0x209d2b0, 0xc000008fa8}, {0x209d550, 0xc000090a40}, {0x209acf0, 0xc0003205b8}, {{0xc00050b2a0?, 0x30000?}}, {{0x0, ...}}, ...) /home/runner/work/chezmoi/chezmoi/pkg/chezmoi/sourcestate.go:578 +0x17f github.com/twpayne/chezmoi/v2/pkg/cmd.(*Config).applyArgs(0xc00050e000, {0x2096c98, 0xc0000340f8}, {0x209d2b0, 0xc000008fa8}, {{0xc00050b2a0?, 0x1a?}}, {0xc00050cd80, 0x0, 0x3}, ...) /home/runner/work/chezmoi/chezmoi/pkg/cmd/config.go:622 +0x846 github.com/twpayne/chezmoi/v2/pkg/cmd.(*Config).runStatusCmd(0xc00050e000, 0xc0002e6000, {0xc00050cd80, 0x0, 0x3}, 0xc000090a80?) /home/runner/work/chezmoi/chezmoi/pkg/cmd/statuscmd.go:72 +0x22d github.com/twpayne/chezmoi/v2/pkg/cmd.(*Config).makeRunEWithSourceState.func1(0xc0002e6000, {0xc00050cd80, 0x0, 0x3}) /home/runner/work/chezmoi/chezmoi/pkg/cmd/config.go:1317 +0x97 github.com/spf13/cobra.(*Command).execute(0xc0002e6000, {0xc00050cd50, 0x3, 0x3}) /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:872 +0x694 github.com/spf13/cobra.(*Command).ExecuteC(0xc000005900) /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:990 +0x3bd github.com/spf13/cobra.(*Command).Execute(...) /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:918 github.com/twpayne/chezmoi/v2/pkg/cmd.(*Config).execute(0xc00099fdf8?, {0xc00004a090, 0x4, 0x7}) /home/runner/work/chezmoi/chezmoi/pkg/cmd/config.go:1189 +0x78 github.com/twpayne/chezmoi/v2/pkg/cmd.runMain({{0x20879d0, 0x6}, {0x20945c0, 0x28}, {0x208b070, 0x14}, {0x20882f8, 0xa}}, {0xc00004a090, 0x4, ...}) /home/runner/work/chezmoi/chezmoi/pkg/cmd/cmd.go:264 +0x1b4 github.com/twpayne/chezmoi/v2/pkg/cmd.Main({{0x20879d0, 0x6}, {0x20945c0, 0x28}, {0x208b070, 0x14}, {0x20882f8, 0xa}}, {0xc00004a090, 0x4, ...}) /home/runner/work/chezmoi/chezmoi/pkg/cmd/cmd.go:128 +0xb1 main.main() /home/runner/work/chezmoi/chezmoi/main.go:26 +0x10c ```

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.22.1, commit 64b9c1fa7346526c17d5073827fe055dc46f6c09, built at 2022-09-04T23:00:07Z, built by goreleaser ok latest-version v2.22.1 ok os-arch windows/amd64 ok systeminfo Microsoft Windows 11 Pro (10.0.22000 N/A Build 22000) ok go-version go1.19 (gc) ok executable C:/ProgramData/chocolatey/lib/chezmoi/tools/chezmoi.exe ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2022-09-10T14:10:44-07:00 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 ok shell-command found C:/WINDOWS/system32/cmd.exe ok shell-args 'C:\\WINDOWS\\system32\\cmd.exe' ok cd-command found C:/Program Files/PowerShell/7-preview/pwsh.exe ok cd-args pwsh -i ok edit-command found C:/Program Files/Microsoft VS Code/bin/code.cmd ok edit-args code --wait info diff-command not set ok git-command found C:/Program Files/Git/cmd/git.exe, version 2.37.3 ok merge-command found C:/Program Files/Microsoft VS Code/bin/code.cmd info age-command age not found in $PATH ok gpg-command found ~/scoop/apps/gnupg/current/bin/gpg.exe, version 2.3.7 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 keeper-command keeper not found in $PATH info keepassxc-db not set info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info vault-command vault not found in $PATH info secret-command not set ```

Additional context

Add any other context about the problem here.

riotrah commented 1 year ago

Oh dang - nevermind.

I knew it had to be due to a missing file.

I realize that it's because I had references to a path that was undefined on windows, in a template, like so:

{{- $fontDir := "" }}
{{- if eq .chezmoi.os "darwin" }}
{{-   $fontDir = "Library/Fonts" }}
{{- else if eq .chezmoi.os "linux" }}
{{-   $fontDir = ".local/share/fonts" }}
{{- end }}

And forgot to have a definition for windows, or at least a null check for $fontDir 😅.