EdenEast / nightfox.nvim

🦊A highly customizable theme for vim and neovim with support for lsp, treesitter and a variety of plugins.
MIT License
2.91k stars 136 forks source link

Took a while to debug cache directory permissions #367

Closed Malien closed 10 months ago

Malien commented 10 months ago

Neovim version (nvim -v)

v0.9.1

Operating system/version

MacOS 13.5.1

Describe the bug

When starting-up nvim with colorscheme nightfox (only the first time, running colorscheme second time changed the colors) or running :NightfoxCompile, I've got the 'ol familiar error: attempt to reference local 'file' which is nil. (line 98 of compiler.lua).

Turns out (I think) I've ran sudo nvim the first time after installing nightfox to edit some system file. As such, cache directory was created under root, and io.open(output_file, "wb") failed due to lacking permissions.

It would've been nice to have a bit of error handling on line 21, so that at least the reason for impossibility of opening a file was surfaced to the end user:

local file, err = io.open(output_file, "wb")
if not file then
    require("nightfox.lib.log").error(fmt(
        [[Couldn't open %s: %s.

Check that %s is accessible for the current user.
You could try deleting %s to reset permissions]],
        output_file,
        err,
        output_file,
        output_path
    ))
    return
end

Not sure this is worth handling, since the steps required to get into such a debacle are really niche, but I thought this was worth reporting anyways.

Steps To Reproduce

  1. sudo nvim
  2. :PackerSync
  3. colorscheme nightfox
  4. Relaunch neovim as unprivileged user
  5. *Profit*

Expected Behavior

Jus surface the error from the io.open. Would've pointed towards solving the issue right away.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "EdenEast/nightfox.nvim",
    config = function()
      require("nightfox").setup({
        -- setup here ...
      })
    end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("nightfox")
EdenEast commented 10 months ago

Thanks for pointing this out. I have created a patch with the suggested changes. Could you let me know if this solves your issue. (Only have access to a machine currently that does not have nvim accessible though root, wsl with nix and home-manager).

Malien commented 10 months ago

Looks good!