refactor: replace vim.uv.* asserts with warn-and-bail

This commit is contained in:
2026-05-02 22:45:24 +02:00
parent 9568fc63a3
commit 8bd674622e
3 changed files with 32 additions and 8 deletions
+2 -2
View File
@@ -58,8 +58,8 @@ local function delete_buffer(force)
if #buffers < 2 then if #buffers < 2 then
return return
end end
local b1 = assert(buffers[1]) local b1 = buffers[1] --[[@as -nil]]
local b2 = assert(buffers[2]) local b2 = buffers[2] --[[@as -nil]]
local current = tonumber(b1:match("^%s*(%d+)")) --[[@as integer?]] local current = tonumber(b1:match("^%s*(%d+)")) --[[@as integer?]]
local previous = tonumber(b2:match("^%s*(%d+)")) --[[@as integer?]] local previous = tonumber(b2:match("^%s*(%d+)")) --[[@as integer?]]
+16 -5
View File
@@ -193,7 +193,11 @@ function M.watch()
return return
end end
watcher = assert(vim.uv.new_fs_event()) local w, err = vim.uv.new_fs_event()
if not w then
util.warning("pack: failed to create fs_event: %s", err)
return
end
local on_change, handle = util.keyed_debounce( local on_change, handle = util.keyed_debounce(
---@param filename string ---@param filename string
function(filename) function(filename)
@@ -210,16 +214,15 @@ function M.watch()
end, end,
200 200
) )
on_change_handle = handle
assert(watcher:start( local ok, err = w:start(
plugins_dir, plugins_dir,
{}, {},
---@param err string? ---@param err string?
---@param filename string ---@param filename string
function(err, filename) function(err, filename)
if err then if err then
log.error("Watch error: %s", err) log.error("pack: watch error for %s: %s", filename, err)
return return
end end
if not filename or not filename:match("%.lua$") then if not filename or not filename:match("%.lua$") then
@@ -227,7 +230,15 @@ function M.watch()
end end
on_change(filename) on_change(filename)
end end
)) )
if not ok then
util.warning("pack: failed to watch %s: %s", plugins_dir, err)
w:close()
handle:close()
return
end
on_change_handle = handle
watcher = w
end end
function M.unwatch() function M.unwatch()
+14 -1
View File
@@ -304,7 +304,20 @@ end
---@param delay integer ---@param delay integer
---@return F, ow.Util.DebounceHandle ---@return F, ow.Util.DebounceHandle
function M.debounce(fn, delay) function M.debounce(fn, delay)
local timer = assert(vim.uv.new_timer()) local timer, err = vim.uv.new_timer()
if not timer then
M.warning("debounce: failed to create timer: %s", err)
local noop = function() end
return fn,
{
cancel = noop,
flush = noop,
pending = function()
return false
end,
close = noop,
}
end
local args ---@type table? local args ---@type table?
local gen = 0 local gen = 0
local fired_gen = 0 local fired_gen = 0