Skip to content

Commit

Permalink
feat: add proper error propagation in async contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Oct 27, 2023
1 parent f245cc7 commit 885c58b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lua/rocks/luarocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ luarocks.cli = function(args, on_exit, opts)
"--lua-version=" .. constants.LUA_VERSION,
"--tree=" .. config.rocks_path,
}, args)
return vim.system(luarocks_cmd, opts, on_exit)
return vim.system(luarocks_cmd, opts, vim.schedule_wrap(on_exit))
end

return luarocks
Expand Down
36 changes: 21 additions & 15 deletions lua/rocks/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ state.installed_rocks = nio.create(function()
"list",
"--porcelain",
}, function(obj)
-- TODO: Error handling
future.set(obj.stdout)
if obj.code ~= 0 then
future.set_error(obj.stderr)
else
future.set(obj.stdout)
end
end, { text = true })

local installed_rock_list = future.wait()
Expand All @@ -58,8 +61,11 @@ state.outdated_rocks = nio.create(function()
"--porcelain",
"--outdated",
}, function(obj)
-- TODO: Error handling
future.set(obj.stdout)
if obj.code ~= 0 then
future.set_error(obj.stderr)
else
future.set(obj.stdout)
end
end, { text = true })

local installed_rock_list = future.wait()
Expand All @@ -80,18 +86,18 @@ state.rock_dependencies = nio.create(function(rock)

local future = nio.control.future()

luarocks.cli(
{
"show",
"--deps",
"--porcelain",
rock.name,
},
vim.schedule_wrap(function(obj)
-- TODO: Error handling
luarocks.cli({
"show",
"--deps",
"--porcelain",
rock.name,
}, function(obj)
if obj.code ~= 0 then
future.set_error(obj.stderr)
else
future.set(obj.stdout)
end, { text = true })
)
end
end, { text = true })

local dependency_list = future.wait()

Expand Down

0 comments on commit 885c58b

Please sign in to comment.