Skip to content

Commit

Permalink
fix(base): update error_msg correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
pysan3 committed Jan 26, 2024
1 parent d2965a5 commit 37bdec1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions lua/pathlib/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ end
---@param recursive boolean # if true, creates parent directories as well
---@return boolean? success
function Path:mkdir(mode, recursive)
if self:is_dir() then
return true
end
if recursive then
local parent = self:parent()
if parent and not parent:is_dir() then
Expand Down
22 changes: 11 additions & 11 deletions lua/pathlib/utils/nuv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ local nio = require("nio")

local M = {}

local function luv_err_msg(self, func, ...)
local result = { func(...) }
if not result[1] then
self.error_msg = result[2]
return nil
end
return unpack(result)
end

if not nio.current_task then
nio.current_task = function()
return require("nio.tasks").current_task()
Expand All @@ -25,16 +16,25 @@ function M.generate_nuv(self)
if nio.current_task() or type(select(-1, ...)) == "function" then
-- is inside async task or is passed a `callback`
local result = { nio.uv[key](...) }
-- result[1]: err_msg or nil
-- result[2, ...]: return values
if result[1] then
self.error_msg = result[1]
end
return unpack(result, 2)
end
local result
if key == "fs_opendir" then
local args = { ... }
return luv_err_msg(self, vim.loop.fs_opendir, args[1], args[3], args[2])
result = { vim.loop.fs_opendir(args[1], args[3], args[2]) }
else
result = { vim.loop[key](...) }
end
if not result[1] then
self.error_msg = result[2]
return nil
end
return luv_err_msg(self, vim.loop[key], ...)
return unpack(result)
end
end,
})
Expand Down

0 comments on commit 37bdec1

Please sign in to comment.