summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-04 11:37:01 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-04 11:37:01 +0100
commita1547bb047dfe66cffa4811d05fb08d98c6d81c6 (patch)
tree959d13c600dd9d052c97adbcb951bf88977cb200
parent5f232e4aaaad5b56d970a425c532e95240f82491 (diff)
downloadsupple-a1547bb047dfe66cffa4811d05fb08d98c6d81c6.tar.gz
SUPPLE: Refine error reporting a little more
-rw-r--r--example/simple-example.lua48
-rw-r--r--lib/supple/comms.lua9
2 files changed, 50 insertions, 7 deletions
diff --git a/example/simple-example.lua b/example/simple-example.lua
index 327167f..af19499 100644
--- a/example/simple-example.lua
+++ b/example/simple-example.lua
@@ -41,15 +41,55 @@ local mt = {
setmetatable(tab, mt)
+local function lprint(...)
+ local foo = {n=select("#",...),...}
+ if foo[1] then
+ print "Function ran OK:"
+ else
+ print "Error encountered:"
+ end
+ for i = 2, foo.n do
+ print(foo[i])
+ end
+ print()
+end
+
-- Finally, run the subcode
-print(supple.host.run(subcode, "@test-code", tab))
+lprint(supple.host.run(subcode, "@test-code", tab))
assert(tab.tot == 24)
-- Now run a supple command which we expect to error out.
-print(supple.host.run("unknown()", "@test-code"))
+lprint(supple.host.run("unknown()", "@test-code"))
-- And now, one where we pass an error from host to sandbox and back
-print(supple.host.run("local f = ... f()", "@test-code", function() unknown() end))
+lprint(supple.host.run("local f = ... f()", "@test-code", function() unknown() end))
-- And now, one where we pass an error from sandbox to host to sandbox and back
-print(supple.host.run("local f = ... f(function() unknown() end)", "@test-code", function(ff) ff() end))
+lprint(supple.host.run("local f = ... f(function() unknown() end)", "@test-code", function(ff) ff() end))
+
+-- And finally, a reasonable traceback via named functions on each end...
+
+local errsrc = [[
+ function raises()
+ does_not_exist()
+ end
+
+ function passes()
+ raises()
+ end
+
+ function chains(f)
+ f(passes)
+ end
+
+ local callme = ...
+
+ callme(chains)
+]]
+
+function loopback(f)
+ f(loopback)
+end
+
+lprint(supple.host.run(errsrc, "@error-code", loopback))
+
diff --git a/lib/supple/comms.lua b/lib/supple/comms.lua
index 25aeb39..d175bff 100644
--- a/lib/supple/comms.lua
+++ b/lib/supple/comms.lua
@@ -20,6 +20,7 @@ local tonumber = tonumber
local error = error
local getinfo = debug.getinfo
local concat = table.concat
+local xpcall = xpcall
local fd = -1
@@ -55,9 +56,11 @@ local function captcha(msg)
local traceback = {}
local level = 2
local info = getinfo(level, "Snlf")
- while info do
- if info.currentline > 0 and
- not info.short_src:match("/supple/[^%.]+%.lua$") then
+ local function in_supple()
+ return info.short_src:match("/supple/[^%.]+%.lua$")
+ end
+ while info and info.func ~= xpcall do
+ if info.currentline > 0 and not in_supple() then
local ttype, tag = objects.find_tag(info.func)
if ttype then
info.name = tag