awful.remote: Run code in a protected context (#2203)
This change makes errors messages show up in the replies, too. Before (notice how the third command does not generate output): $ awesome-client 'return 42' ; awesome-client 'sdfsdf' ; awesome-client 'error("foo")' double 42 string "[string "sdfsdf"]:1: syntax error near <eof>" After: $ awesome-client 'return 42' ; awesome-client 'sdfsdf' ; awesome-client 'error("foo")' double 42 string "[string "sdfsdf"]:1: syntax error near <eof>" string "Error during execution: [string "error("foo")"]:1: foo" Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
f9eec13144
commit
44587cec35
|
@ -20,8 +20,13 @@ if dbus then
|
||||||
dbus.connect_signal("org.awesomewm.awful.Remote", function(data, code)
|
dbus.connect_signal("org.awesomewm.awful.Remote", function(data, code)
|
||||||
if data.member == "Eval" then
|
if data.member == "Eval" then
|
||||||
local f, e = load(code)
|
local f, e = load(code)
|
||||||
if f then
|
if not f then
|
||||||
local results = { f() }
|
return "s", e
|
||||||
|
end
|
||||||
|
local results = { pcall(f) }
|
||||||
|
if not table.remove(results, 1) then
|
||||||
|
return "s", "Error during execution: " .. results[1]
|
||||||
|
end
|
||||||
local retvals = {}
|
local retvals = {}
|
||||||
for _, v in ipairs(results) do
|
for _, v in ipairs(results) do
|
||||||
local t = type(v)
|
local t = type(v)
|
||||||
|
@ -37,9 +42,6 @@ if dbus then
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return unpack(retvals)
|
return unpack(retvals)
|
||||||
elseif e then
|
|
||||||
return "s", e
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue