Include stack trace in effect errors (#91)
Some checks are pending
unit-test / unit-test (push) Waiting to run

This commit is contained in:
Olaroll 2026-09-24 13:33:03 +03:00 • committed by GitHub
parent f3bfc65607
commit 2adbf16f8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,7 +31,14 @@ local function efn(err: string)
end end
trace ..= "\nsource update stacktrace:" trace ..= "\nsource update stacktrace:"
return trace return trace
end
local function effect_traceback(err: unknown): string
local message = tostring(err)
-- Nested effect error already has full thread stack
if string.find(message, "^effect error:\n") then return message end
return `effect error:\n{debug.traceback(message, 2)}`
end end
local function ycall<T, U>(fn: (T) -> U, arg: T): (boolean, string|U) local function ycall<T, U>(fn: (T) -> U, arg: T): (boolean, string|U)
@ -181,13 +188,13 @@ local function evaluate_node<T>(node: Node<T>)
destroy_owned(node) destroy_owned(node)
push_scope(node) push_scope(node)
local ok, new_value = pcall(node.effect :: (T) -> T, node.cache) local ok, new_value = xpcall(node.effect :: (T) -> T, effect_traceback, node.cache)
pop_scope() pop_scope()
if not ok then if not ok then
table.clear(update_queue) table.clear(update_queue)
update_queue.n = 0 update_queue.n = 0
error(`effect error:\n{new_value}\n`, 0) error(new_value, 0)
end end
node.cache = new_value node.cache = new_value