chore: better uv.spawn error handling and windows git spawn bugfix (#1498)
This commit is contained in:
@@ -20,9 +20,14 @@ function AsyncJob.new(opts)
|
|||||||
self.stdout = opts.stdout or M.NullPipe()
|
self.stdout = opts.stdout or M.NullPipe()
|
||||||
self.stderr = opts.stderr or M.NullPipe()
|
self.stderr = opts.stderr or M.NullPipe()
|
||||||
|
|
||||||
if opts.cwd then
|
if opts.cwd and opts.cwd ~= "" then
|
||||||
-- TODO: not vim.fn
|
|
||||||
self.uv_opts.cwd = vim.fn.expand(opts.cwd)
|
self.uv_opts.cwd = vim.fn.expand(opts.cwd)
|
||||||
|
-- this is a "illegal" hack for windows. E.g. If the git command returns `/` rather than `\` as delimiter,
|
||||||
|
-- vim.fn.expand might just end up returning an empty string. Weird
|
||||||
|
-- Because empty string is not allowed in libuv the job will not spawn. Solution is we just set it to opts.cwd
|
||||||
|
if self.uv_opts.cwd == "" then
|
||||||
|
self.uv_opts.cwd = opts.cwd
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.uv_opts.stdio = {
|
self.uv_opts.stdio = {
|
||||||
@@ -57,8 +62,7 @@ end
|
|||||||
|
|
||||||
M.spawn = function(opts)
|
M.spawn = function(opts)
|
||||||
local self = AsyncJob.new(opts)
|
local self = AsyncJob.new(opts)
|
||||||
|
self.handle, self.pid = uv.spawn(
|
||||||
self.handle = uv.spawn(
|
|
||||||
self.command,
|
self.command,
|
||||||
self.uv_opts,
|
self.uv_opts,
|
||||||
async.void(function()
|
async.void(function()
|
||||||
@@ -66,6 +70,10 @@ M.spawn = function(opts)
|
|||||||
end)
|
end)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not self.handle then
|
||||||
|
error(debug.traceback("Failed to spawn process: " .. vim.inspect(self)))
|
||||||
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user