Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With edit.hardlink disabled, chezmoi has nonzero exit status after exiting editor #3574

Closed
terminalmage opened this issue Feb 16, 2024 · 10 comments
Labels
in dependency In a dependency, not in chezmoi not a bug Not a bug in chezmoi

Comments

@terminalmage
Copy link

terminalmage commented Feb 16, 2024

Describe the bug

Per https://github.com/twpayne/chezmoi/pull/3573/files, I disabled edit.hardlink to be able to use an autocommand to automatically apply changes. However, when writing a buffer and exiting neovim via :wq, chezmoi exits with nonzero exit status, and the following is written to stderr:

chezmoi: exit status 134

To reproduce

  1. Configure the following vim autocommand:
    autocmd BufWritePost ~/.local/share/chezmoi/* ! chezmoi apply --source-path "%"
  2. Disable edit.hardlink using the following in ~/.config/chezmoi/chezmoi.toml:
    [edit]
        hardlink = false
  3. Edit a chezmoi-managed file using chezmoi edit ~/path/to/file
  4. Save and exit using :wq.

NOTE: The nonzero exit status only happens when saving and exiting at the same time. If you separately use :w to save the buffer, and :q to exit, the changes are applied and chezmoi exits normally.

Expected behavior

chezmoi exits normally

Output of command with the --verbose flag

No additional output

Output of chezmoi doctor

RESULT    CHECK                       MESSAGE
ok        version                     v2.45.0, commit 371703e93f0c54dad81f7cfbea2906ece15a7428, built at 2024-01-13T20:01:02Z, built by goreleaser
warning   latest-version              v2.46.1
ok        os-arch                     linux/amd64 (Ubuntu 20.04.6 LTS (Focal Fossa))
ok        uname                       Linux chi-lps2kmx1 5.15.0-92-generic #102~20.04.1-Ubuntu SMP Mon Jan 15 13:09:14 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
ok        go-version                  go1.21.6 (gc)
ok        executable                  ~/.local/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
ok        umask                       022
ok        cd-command                  found /usr/bin/zsh
ok        cd-args                     /usr/bin/zsh
info      diff-command                not set
ok        edit-command                found ~/neovim/current/bin/nvim
ok        edit-args                   ~/neovim/current/bin/nvim
ok        git-command                 found /usr/bin/git, version 2.25.1
ok        merge-command               found /usr/bin/vimdiff
ok        shell-command               found /usr/bin/zsh
ok        shell-args                  /usr/bin/zsh
info      age-command                 age not found in $PATH
ok        gpg-command                 found /usr/bin/gpg, version 2.2.19
info      pinentry-command            not set
info      1password-command           op not found in $PATH
info      bitwarden-command           bw not found in $PATH
info      bitwarden-secrets-command   bws not found in $PATH
info      dashlane-command            dcli not found in $PATH
info      doppler-command             doppler 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      rbw-command                 rbw not found in $PATH
info      vault-command               vault not found in $PATH
info      vlt-command                 vlt not found in $PATH
info      secret-command              not set
@twpayne
Copy link
Owner

twpayne commented Feb 16, 2024

I'm unable to reproduce this problem on macOS with nvim v0.9.5 and chezmoi v2.46.1. For me, the autocommand works as a expected and chezmoi applies the file on write and exits successfully.

Could you give steps to reproduce the problem in an isolated environment, e.g. a docker container?

Alternatively, if you add --debug to the chezmoi apply command, what do you see?

autocmd BufWritePost ~/.local/share/chezmoi/* ! chezmoi apply --debug --source-path "%"

@twpayne twpayne added the investigating This is a bit weird, not sure if this is a bug yet label Feb 16, 2024
@terminalmage
Copy link
Author

I upgraded to 2.46.1, and am running neovim 0.9.5 as well. Still getting the error. This is on Ubuntu 20.04.

The debug logging disappears when nvim exits, so I can only get that logging when I write the buffer using :w. Here's that debug output, but keep in mind that the bad exit status for chezmoi only happens when I run :wq.

time=2024-02-16T12:46:25.585-06:00 level=INFO msg=ReadDir component=systemname=/home/erik/.local/share/chezmoi/dot_vim/pack/erik/start/user-defined
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=ReadDir component=systemname=/home/erik/.local/share/chezmoi/dot_vim/pack/erik/start/user-defined/colors
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=ReadDir component=systemname=/home/erik/.local/share/chezmoi/dot_vim/pack/erik/start/user-defined/ftdetect
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=ReadDir component=systemname=/home/erik/.local/share/chezmoi/dot_vim/pack/erik/start/user-defined/ftplugin
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=ReadDir component=systemname=/home/erik/.local/share/chezmoi/dot_vim/pack/erik/start/user-defined/syntax
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=ReadDir component=systemname=/home/erik/.local/share/chezmoi/private_dot_gnupg
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=ReadDir component=system name=/home/erik/.local/share/chezmoi/private_dot_ssh
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=ReadFile component=system name=/home/erik/.local/share/chezmoi/dot_vimrc size=3371 data="\" Status line\nset statusline=%F%M%r%h%w\\ %y\\ [%{&ff}]\\ ascii=\\%0..."
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=Lstat component=system n ame=/home/erik/.vimrc
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=Get component=persistentState bucket=entryState key=/home/erik/.vimrc value="{\n  \"type\": \"file\",\n  \"mode\": 420,\n  \"contentsSHA256\": \"39bc8626cbe3cbc60e1e6a337865df3e46bc9e536112748945bf8326946519c9\"\n}\n"
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=ReadFile component=system name=/home/erik/.vimrc size=3371 data="\" Status line\nset statusline=%F%M%r%h%w\\ %y\\ [%{&ff}]\\ ascii=\\%0..."
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=defaultPreApplyFunc targetRelPath=.vimrc targetEntryState.Type=file targetEntryState.Mode=420 targetEntryState.ContentsSHA256=39bc8626cbe3cbc60e1e6a337865df3e46bc9e536112748945bf8326946519c9 targetEntryState.contents="\" Status line\nset statusline=%F%M%r%h%w\\ %y\\ [%{&ff}]\\ ascii=\\%0..." lastWrittenEntryState.Type=file lastWrittenEntryState.Mode=420 lastWrittenEntryState.ContentsSHA256=39bc8626cbe3cbc60e1e6a337865df3e46bc9e536112748945bf8326946519c9 actualEntryState.Type=file actualEntryState.Mode=420 actualEntryState.ContentsSHA256=39bc8626cbe3cbc60e1e6a337865df3e46bc9e536112748945bf8326946519c9 actualEntryState.contents="\" Status line\nset statusline=%F%M%r%h%w\\ %y\\ [%{&ff}]\\ ascii=\\%0..."
time=2024-02-16T12:46:25.585-06:00 level=INFO msg=Close component=persistentState

I can reproduce this on Arch Linux with the same versions of chezmoi and neovim.

@terminalmage
Copy link
Author

terminalmage commented Feb 16, 2024

Will have to wait until later to try to reproduce in Docker.

@terminalmage
Copy link
Author

One weird detail: On Arch Linux, I forgot to add the chezmoi.toml, and I still see the same error. Also, files open in ~/.local/share/chezmoi when chezmoi edit is invoked. I'm not sure why it does that when I had to disable edit.hardlink to get it to open the files there on Ubuntu.

@twpayne
Copy link
Owner

twpayne commented Feb 16, 2024

Ah, I can now reproduce this. Interestingly, the autocmd works when you write the file from nvim (:w) but I also get the chezmoi: exit status 134 error when you write and quit nvim (:wq). So, I currently suspect some nvim weirdness.

@terminalmage
Copy link
Author

terminalmage commented Feb 16, 2024

Yeah, the autocmd works in both cases (:w then :q, or :wq). The changes do get successfully applied as expected in both cases. But only :wq causes chezmoi to exit nonzero.

@twpayne
Copy link
Owner

twpayne commented Feb 16, 2024

So, it turns out that chezmoi is doing the right thing here. nvim is exiting with exit code 134, which is non-zero and therefore indicates failure. Exit code 134 typically means that the process received a SIGABRT. chezmoi is faithfully reporting nvim's self-reported failure. #3577 improves chezmoi's logging of all subprocesses it runs.

This is definitely a bug in NeoVim. I can reproduce it without involving chezmoi. I'll create an issue there.

@twpayne
Copy link
Owner

twpayne commented Feb 16, 2024

I've opened neovim/neovim#27499. As this is a bug in Neovim, I'll close this issue.

@twpayne twpayne closed this as completed Feb 16, 2024
@twpayne twpayne added in dependency In a dependency, not in chezmoi not a bug Not a bug in chezmoi and removed investigating This is a bit weird, not sure if this is a bug yet labels Feb 16, 2024
@terminalmage
Copy link
Author

Excellent, thanks so much for looking into it.

@terminalmage
Copy link
Author

BTW @twpayne, I grabbed a pre-built nightly from here and cannot reproduce the bug with it. So it would appear that v0.10 should fix this.

Thanks again for taking the time to diagnose and report this upstream (even though it was closed as a duplicate).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in dependency In a dependency, not in chezmoi not a bug Not a bug in chezmoi
Projects
None yet
Development

No branches or pull requests

2 participants