aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-04-11 14:48:04 +0200
committerWilliam Boman <william@redwill.se>2022-04-11 14:59:09 +0200
commit50f5ce660fa2898685c365344321fcadaeeab717 (patch)
tree164eadd04f1cde4307be59b578b1e058deb04ec9
parentmake install context available via coroutine context (#586) (diff)
downloadmason-50f5ce660fa2898685c365344321fcadaeeab717.tar
mason-50f5ce660fa2898685c365344321fcadaeeab717.tar.gz
mason-50f5ce660fa2898685c365344321fcadaeeab717.tar.bz2
mason-50f5ce660fa2898685c365344321fcadaeeab717.tar.lz
mason-50f5ce660fa2898685c365344321fcadaeeab717.tar.xz
mason-50f5ce660fa2898685c365344321fcadaeeab717.tar.zst
mason-50f5ce660fa2898685c365344321fcadaeeab717.zip
fix(spawn): fix Failure.tostring when unable to retrieve uv_handle
-rw-r--r--lua/nvim-lsp-installer/core/spawn.lua6
-rw-r--r--tests/core/spawn_spec.lua31
2 files changed, 36 insertions, 1 deletions
diff --git a/lua/nvim-lsp-installer/core/spawn.lua b/lua/nvim-lsp-installer/core/spawn.lua
index 4776ff66..8ac06aa4 100644
--- a/lua/nvim-lsp-installer/core/spawn.lua
+++ b/lua/nvim-lsp-installer/core/spawn.lua
@@ -24,7 +24,11 @@ local spawn = {
local function Failure(err, cmd)
return Result.failure(setmetatable(err, {
__tostring = function()
- return ("spawn: %s failed with exit code %d"):format(cmd, err.exit_code)
+ if err.exit_code ~= nil then
+ return ("spawn: %s failed with exit code %d. %s"):format(cmd, err.exit_code, err.stderr or "")
+ else
+ return ("spawn: %s failed with no exit code. %s"):format(cmd, err.stderr or "")
+ end
end,
}))
end
diff --git a/tests/core/spawn_spec.lua b/tests/core/spawn_spec.lua
index 176135ee..7c0a27f8 100644
--- a/tests/core/spawn_spec.lua
+++ b/tests/core/spawn_spec.lua
@@ -1,4 +1,5 @@
local spy = require "luassert.spy"
+local stub = require "luassert.stub"
local match = require "luassert.match"
local spawn = require "nvim-lsp-installer.core.spawn"
local process = require "nvim-lsp-installer.process"
@@ -113,4 +114,34 @@ describe("async spawn", function()
assert.is_true(result:is_failure())
end)
)
+
+ it(
+ "should handle failure to spawn process",
+ async_test(function()
+ stub(process, "spawn", function(_, _, callback)
+ callback(false)
+ end)
+
+ local result = spawn.my_cmd {}
+ assert.is_true(result:is_failure())
+ assert.is_nil(result:err_or_nil().exit_code)
+ end)
+ )
+
+ it(
+ "should format failure message",
+ async_test(function()
+ stub(process, "spawn", function(cmd, opts, callback)
+ opts.stdio_sink.stderr(("This is an error message for %s!"):format(cmd))
+ callback(false, 127)
+ end)
+
+ local result = spawn.my_cmd {}
+ assert.is_true(result:is_failure())
+ assert.equals(
+ "spawn: my_cmd failed with exit code 127. This is an error message for my_cmd!",
+ tostring(result:err_or_nil())
+ )
+ end)
+ )
end)