From 8bd674622e46996d7f14b5ac273911e02be6e641 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Sat, 2 May 2026 22:45:24 +0200 Subject: [PATCH] refactor: replace vim.uv.* asserts with warn-and-bail --- lua/core/keymap.lua | 4 ++-- lua/pack.lua | 21 ++++++++++++++++----- lua/util.lua | 15 ++++++++++++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lua/core/keymap.lua b/lua/core/keymap.lua index 5ee4ecc..00e1492 100644 --- a/lua/core/keymap.lua +++ b/lua/core/keymap.lua @@ -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?]] diff --git a/lua/pack.lua b/lua/pack.lua index 14da174..6240605 100644 --- a/lua/pack.lua +++ b/lua/pack.lua @@ -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() diff --git a/lua/util.lua b/lua/util.lua index 39c3425..6f545c1 100644 --- a/lua/util.lua +++ b/lua/util.lua @@ -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