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

Error printed on first autocompletion menu: "couldn't create cache-dir /zsh/compcache" #262

Closed
tomKPZ opened this issue May 20, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@tomKPZ
Copy link

tomKPZ commented May 20, 2021

This bug only repros when I set:
zstyle ':completion:*' extra-verbose true

The issue is that .autocomplete.config sets cache-path to "$XDG_CACHE_HOME/zsh/compcache", but my XDG_CACHE_HOME is not set. According to the XDG spec [1], "If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used."

[1] https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

@tomKPZ tomKPZ added the bug Something isn't working label May 20, 2021
@marlonrichert
Copy link
Owner

my XDG_CACHE_HOME is not set.

Are you sure? Because it gets set here:

export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"

@tomKPZ
Copy link
Author

tomKPZ commented May 20, 2021

I'm sure. I can see it's empty if I "echo $XDG_CACHE_HOME" at the end of my .zshrc. I think the issue is that .autocomplete.init.precmd runs after .zshrc.

Also zsh-autocomplete should not be exporting XDG_CACHE_HOME/XDG_DATA_HOME. It should just use "${XDG_CACHE_HOME:-$HOME/.cache}" where appropriate, or use "local" instead of "export".

@marlonrichert
Copy link
Owner

marlonrichert commented May 20, 2021

I think the issue is that .autocomplete.init.precmd runs after .zshrc.

Yes, that is intentional.

Also zsh-autocomplete should not be exporting XDG_CACHE_HOME/XDG_DATA_HOME. It should just use "${XDG_CACHE_HOME:-$HOME/.cache}" where appropriate, or use "local" instead of "export".

Sure, I can change that.

Anyway, I cannot reproduce this. Can you please use the bug report template that you deleted when you created this issue to make a reproducible test case? It doesn't have this warning for nothing, you know:

⚠️ DO NOT DELETE the template below. Instead, use it to put together a minimal test case with
which I can reproduce the bug. If I cannot reproduce the bug, then I cannot fix it!

@marlonrichert marlonrichert added question Further information is requested and removed bug Something isn't working labels May 20, 2021
@tomKPZ
Copy link
Author

tomKPZ commented May 20, 2021

The repro steps are:

$ git -C ~zsh-autocomplete switch main  # Make sure you test with the `main` branch.
$ git -C ~zsh-autocomplete pull         # Update to the latest commit.
$ cd $(mktemp -d)                       # Create a temp dir and enter it.
$ unset _comp_dumpfile ZDOTDIR XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME
$ HOME=$PWD exec zsh -f       # Restart Zsh without config files in this dir.
% source /path/to/zsh-autocomplete/zsh-autocomplete.plugin.zsh
% zstyle ':completion:*' extra-verbose true
% l

Upon typing "l", I get "couldn't create cache-dir /zsh/compcache". The error is not shown again.

The key to getting this to reproduce for me is zstyle ':completion:*' extra-verbose true.

I think the issue is that .autocomplete.init.precmd runs after .zshrc.

Yes, that is intentional.

That explains why the issue is occurring. At the time .autocomplete.config runs, XDG_CACHE_HOME is unset, which means [1]:
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/compcache"
will expand to:
zstyle ':completion:*' cache-path "/zsh/compcache"

[1] https://github.com/marlonrichert/zsh-autocomplete/blob/main/module/.autocomplete.config#L15

@marlonrichert
Copy link
Owner

That explains why the issue is occurring. At the time .autocomplete.config runs, XDG_CACHE_HOME is unset, which means [1]:
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/compcache"
will expand to:
zstyle ':completion:*' cache-path "/zsh/compcache"

Thanks. I can confirm that is indeed the case. Will fix.

@marlonrichert marlonrichert self-assigned this May 20, 2021
@marlonrichert marlonrichert added bug Something isn't working and removed question Further information is requested labels May 20, 2021
marlonrichert added a commit that referenced this issue May 22, 2021
@marlonrichert
Copy link
Owner

Fixed.

@tomKPZ
Copy link
Author

tomKPZ commented May 22, 2021

Woo! Thank you very much for the fix!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants