feat: better error handling for chmod command
This commit is contained in:
@@ -11,6 +11,15 @@ local selected_or_hovered = ya.sync(function()
|
||||
return paths
|
||||
end)
|
||||
|
||||
local function fail(s, ...)
|
||||
ya.notify {
|
||||
title = "Chmod",
|
||||
content = string.format(s, ...),
|
||||
level = "error",
|
||||
timeout = 5,
|
||||
}
|
||||
end
|
||||
|
||||
return {
|
||||
entry = function()
|
||||
ya.emit("escape", { visual = true })
|
||||
@@ -29,14 +38,11 @@ return {
|
||||
return
|
||||
end
|
||||
|
||||
local status, err = Command("chmod"):arg(value):arg(urls):spawn():wait()
|
||||
if not status or not status.success then
|
||||
ya.notify {
|
||||
title = "Chmod",
|
||||
content = string.format("Chmod on selected files failed, error: %s", status and status.code or err),
|
||||
level = "error",
|
||||
timeout = 5,
|
||||
}
|
||||
local output, err = Command("chmod"):arg(value):arg(urls):stderr(Command.PIPED):output()
|
||||
if not output then
|
||||
fail("Failed to run chmod: %s", err)
|
||||
elseif not output.status.success then
|
||||
fail("Chmod failed with stderr:\n%s", output.stderr:gsub("^chmod:%s*", ""))
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user