diff options
| author | William Boman <william@redwill.se> | 2022-04-11 14:48:04 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2022-04-11 14:59:09 +0200 |
| commit | 50f5ce660fa2898685c365344321fcadaeeab717 (patch) | |
| tree | 164eadd04f1cde4307be59b578b1e058deb04ec9 | |
| parent | make install context available via coroutine context (#586) (diff) | |
| download | mason-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.lua | 6 | ||||
| -rw-r--r-- | tests/core/spawn_spec.lua | 31 |
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) |
