Skip to content

Commit

Permalink
fix: check that handler callbacks are set before trying to call them
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored and vhyrro committed Feb 29, 2024
1 parent de964da commit 02a2749
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lua/rocks/operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ end, 1)
---@return rock_handler_callback | nil
local function get_install_handler_callback(rocks_toml_ref, arg_list)
return vim.iter(_handlers)
:filter(function(handler)
---@cast handler RockHandler
return type(handler.get_install_callback) == "function"
end)
:map(function(handler)
---@cast handler RockHandler
local get_callback = handler.get_install_callback
Expand All @@ -69,10 +73,13 @@ end
---@return rock_handler_callback | nil
local function get_sync_handler_callback(spec)
return vim.iter(_handlers)
:filter(function(handler)
---@cast handler RockHandler
return type(handler.get_sync_callback) == "function"
end)
:map(function(handler)
---@cast handler RockHandler
local get_callback = handler.get_sync_callback
return type(get_callback) == "function" and get_callback(spec)
return handler.get_sync_callback(spec)
end)
:find(function(callback)
return callback ~= nil
Expand All @@ -83,6 +90,10 @@ end
---@return rock_handler_callback[]
local function get_update_handler_callbacks(rocks_toml_ref)
return vim.iter(_handlers)
:filter(function(handler)
---@cast handler RockHandler
return type(handler.get_update_callbacks) == "function"
end)
:map(function(handler)
---@cast handler RockHandler
return handler.get_update_callbacks(rocks_toml_ref) or {}
Expand Down

0 comments on commit 02a2749

Please sign in to comment.