From 9269a0ecc7267822bc5ac5af95ad4977bdc94fec Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Thu, 29 Oct 2015 14:48:10 -0400 Subject: Fix server crashing on Lua errors Previously, the server called FATAL_ERROR when a Lua error occured. This caused a (mostly useless) core dump. The server now simply throws an exception, which is caught and printed before exiting with a non-zero return value. This also fixes a number of instances where errors were logged multiple times. --- src/main.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 1fa9243fa..b24ece4bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -816,14 +816,22 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings & if (cmd_args.exists("migrate")) return migrate_database(game_params, cmd_args); - // Create server - Server server(game_params.world_path, game_params.game_spec, false, - bind_addr.isIPv6()); - server.start(bind_addr); - - // Run server - bool &kill = *porting::signal_handler_killstatus(); - dedicated_server_loop(server, kill); + try { + // Create server + Server server(game_params.world_path, game_params.game_spec, false, + bind_addr.isIPv6()); + server.start(bind_addr); + + // Run server + bool &kill = *porting::signal_handler_killstatus(); + dedicated_server_loop(server, kill); + } catch (const ModError &e) { + errorstream << "ModError: " << e.what() << std::endl; + return false; + } catch (const ServerError &e) { + errorstream << "ServerError: " << e.what() << std::endl; + return false; + } return true; } -- cgit v1.2.3