lewis6991 / impatient.nvim

Improve startup time for Neovim
MIT License
1.19k stars 28 forks source link

Attempt to index nil error when original source doesn't exist #5

Closed shadmansaleh closed 3 years ago

shadmansaleh commented 3 years ago

Issue:

The stat call here can return nil when the modpath doesn't exist https://github.com/lewis6991/impatient.nvim/blob/d9bf2648836d6338973ac000aa0cb1bdc21f87e0/lua/impatient.lua#L68 This should be handled .

Cause:

Since hash is called at startup on cached filepaths you can't guarantee that location is still valid. https://github.com/lewis6991/impatient.nvim/blob/d9bf2648836d6338973ac000aa0cb1bdc21f87e0/lua/impatient.lua#L111

Trigger:

Already cached plugin being uninstalled.

Possible solution:

diff --git a/lua/impatient.lua b/lua/impatient.lua
index 367411f..2eef442 100644
--- a/lua/impatient.lua
+++ b/lua/impatient.lua
@@ -65,7 +65,9 @@ do
   end

   local function hash(modpath)
-    return vim.loop.fs_stat(modpath).mtime.sec
+    local stat = vim.loop.fs_stat(modpath)
+    if not stat then return nil end
+    return stat.mtime.sec
   end

   local function load_package_with_cache(name)