You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pcall discards state mutations made before error() (diverges from reference Lua) #331
When a function called via pcall raises an error, any state mutations made before the error() call are rolled back. Reference Lua keeps those mutations; pcall only traps the error and returns false, err without unwinding side effects.
Counters incremented before a failed call (step = step + 1; risky())
Partial progress recorded for retry/resume logic
"Mutate then validate, error on bad result" patterns
Logging or audit trail writes inside the protected block
All of these silently lose their effects.
Root cause
In lib/lua.ex, do_call_function/3's rescue clause returns the original state parameter rather than the partially-mutated state accumulated during execution:
defpdo_call_function({:lua_closure,proto,upvalues},args,state)do...{results,_regs,new_state}=Executor.execute(proto.instructions,callee_regs,upvalues,proto,state){:ok,results,new_state}rescuee->{:error,Exception.message(e),state}# <- should thread out the partial new_stateend
The same pattern repeats in the :native_func and :compiled_closure clauses. To match reference Lua, the executor needs to thread the mutated state out through the raise (e.g., attach it to a struct exception) so the rescue can return {:error, msg, partial_state} instead of the pre-call snapshot.
Activity
fix(lua): ferry state out of user-function error tuples under pcall
fix(lua): ferry state out of user-function error tuples under pcall