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

Took a while to debug cache directory permissions #367

Closed
Malien opened this issue Sep 4, 2023 · 2 comments
Closed

Took a while to debug cache directory permissions #367

Malien opened this issue Sep 4, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Malien
Copy link

Malien commented Sep 4, 2023

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")
@Malien Malien added the bug Something isn't working label Sep 4, 2023
@EdenEast
Copy link
Owner

EdenEast commented Sep 4, 2023

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
Copy link
Author

Malien commented Sep 5, 2023

Looks good!

@EdenEast EdenEast closed this as completed Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants