From 766e885a1b1c5afb7a62f11b427b6d135adeab87 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 10 Sep 2021 23:16:46 +0200 Subject: Clean up/improve some scriptapi error handling code --- src/script/cpp_api/s_env.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'src/script/cpp_api/s_env.cpp') diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp index c11de3757..874c37b6e 100644 --- a/src/script/cpp_api/s_env.cpp +++ b/src/script/cpp_api/s_env.cpp @@ -53,13 +53,7 @@ void ScriptApiEnv::environment_Step(float dtime) lua_getfield(L, -1, "registered_globalsteps"); // Call callbacks lua_pushnumber(L, dtime); - try { - runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); - } catch (LuaError &e) { - getServer()->setAsyncFatalError( - std::string("environment_Step: ") + e.what() + "\n" - + script_get_backtrace(L)); - } + runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiEnv::player_event(ServerActiveObject *player, const std::string &type) @@ -76,13 +70,7 @@ void ScriptApiEnv::player_event(ServerActiveObject *player, const std::string &t // Call callbacks objectrefGetOrCreate(L, player); // player lua_pushstring(L,type.c_str()); // event type - try { - runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); - } catch (LuaError &e) { - getServer()->setAsyncFatalError( - std::string("player_event: ") + e.what() + "\n" - + script_get_backtrace(L) ); - } + runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env) @@ -257,9 +245,8 @@ void ScriptApiEnv::on_emerge_area_completion( try { PCALL_RES(lua_pcall(L, 4, 0, error_handler)); } catch (LuaError &e) { - server->setAsyncFatalError( - std::string("on_emerge_area_completion: ") + e.what() + "\n" - + script_get_backtrace(L)); + // Note: don't throw here, we still need to run the cleanup code below + server->setAsyncFatalError(e); } lua_pop(L, 1); // Pop error handler @@ -300,4 +287,4 @@ void ScriptApiEnv::on_liquid_transformed( } runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); -} \ No newline at end of file +} -- cgit v1.2.3