poga / actix-lua

Safe Lua Scripting Environment for Actix
MIT License
121 stars 13 forks source link

Option to not panic when `error()` is called in Lua script #17

Closed poga closed 5 years ago

poga commented 5 years ago

Before 0.4.0 and 0.3.4, if error() 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 in actor.rs. Maybe we should return a Err instead of just panic!.

poga commented 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.

poga commented 5 years ago

https://github.com/poga/actix-lua/commit/67e15ca90785820e1c06fbc8b273fcf3eb49372b added an example about hot-reloading with pcall. I think this is good enough.

Arnaz87 commented 5 years ago

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.

poga commented 5 years ago

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?

Arnaz87 commented 5 years ago

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.

poga commented 5 years ago

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.

Arnaz87 commented 5 years ago

I see, then the only option would be to run lua in debug mode? Is that possible in actix-lua?

poga commented 5 years ago

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.