Closed poga closed 5 years ago
Another solution is to wrap our own script in a pcall
and do the error handling in Lua. It might be a better solution.
https://github.com/poga/actix-lua/commit/67e15ca90785820e1c06fbc8b273fcf3eb49372b added an example about hot-reloading with pcall
. I think this is good enough.
This solution doesn't allow one access to the error information, because the debug library is disabled for safety reasons, rlua's error implements the failure crate's trait so it has very useful information.
pcall
does return error message and loc as its second return value.
Are you trying to handle lua error with Rust? Can you provide an example about what you want to achieve?
I need to log the stack trace of the error, sometimes only the loc isn't enough to track down an error, but inside lua the trace is only accesible in debug.traceback, which is disallowed.
From what I understand, rlua::Error.backtrace()
is only implemented for ExternalError
. (https://github.com/kyren/rlua/blob/master/src/error.rs#L194). An ExternalError
is used when you want to return error from rust callbacks to lua. Hence it's not really useful for debugging Lua errors.
I see, then the only option would be to run lua in debug mode? Is that possible in actix-lua?
rlua
does provide an unsafe method for loading debug library into lua state. We can have an unsafe new_with_debug
method for LuaActorBuilder
to build a LuaActor
with the debug library.
I've opened https://github.com/poga/actix-lua/issues/18. Feel free to tackle it.
Before
0.4.0
and0.3.4
, iferror()
is called inside the Lua script, it will be consumed silently. Now it will panic with proper stack trace.It's easiler to debug now. But, sometimes panicking is too destructive. One use-case is a live-reloading environment. We might want to just show the error trace and continue the execution, allows user to have a chance to fix their script without restarting the whole program.
This is mostly about the last part of the
invoke
function inactor.rs
. Maybe we should return aErr
instead of justpanic!
.