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