refactor: replace vim.uv.* asserts with warn-and-bail
This commit is contained in:
+2
-2
@@ -58,8 +58,8 @@ local function delete_buffer(force)
|
||||
if #buffers < 2 then
|
||||
return
|
||||
end
|
||||
local b1 = assert(buffers[1])
|
||||
local b2 = assert(buffers[2])
|
||||
local b1 = buffers[1] --[[@as -nil]]
|
||||
local b2 = buffers[2] --[[@as -nil]]
|
||||
|
||||
local current = tonumber(b1:match("^%s*(%d+)")) --[[@as integer?]]
|
||||
local previous = tonumber(b2:match("^%s*(%d+)")) --[[@as integer?]]
|
||||
|
||||
+16
-5
@@ -193,7 +193,11 @@ function M.watch()
|
||||
return
|
||||
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(
|
||||
---@param filename string
|
||||
function(filename)
|
||||
@@ -210,16 +214,15 @@ function M.watch()
|
||||
end,
|
||||
200
|
||||
)
|
||||
on_change_handle = handle
|
||||
|
||||
assert(watcher:start(
|
||||
local ok, err = w:start(
|
||||
plugins_dir,
|
||||
{},
|
||||
---@param err string?
|
||||
---@param filename string
|
||||
function(err, filename)
|
||||
if err then
|
||||
log.error("Watch error: %s", err)
|
||||
log.error("pack: watch error for %s: %s", filename, err)
|
||||
return
|
||||
end
|
||||
if not filename or not filename:match("%.lua$") then
|
||||
@@ -227,7 +230,15 @@ function M.watch()
|
||||
end
|
||||
on_change(filename)
|
||||
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
|
||||
|
||||
function M.unwatch()
|
||||
|
||||
+14
-1
@@ -304,7 +304,20 @@ end
|
||||
---@param delay integer
|
||||
---@return F, ow.Util.DebounceHandle
|
||||
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 gen = 0
|
||||
local fired_gen = 0
|
||||
|
||||
Reference in New Issue
Block a user