mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-04 23:06:08 +00:00
handle all exceptions which happen inside a logging macro
and print them ;)
This commit is contained in:
105
include/Common.h
105
include/Common.h
@@ -150,7 +150,7 @@ public:
|
||||
|
||||
// Keeps track of how many packets we dropped on UDP due to fundamentally being malformed
|
||||
static inline std::atomic_size_t MalformedUdpPackets { 0 };
|
||||
// Keeps track of how many packets we dropped on UDP due to
|
||||
// Keeps track of how many packets we dropped on UDP due to
|
||||
// 1) not having a valid (known) player id
|
||||
// 2) player disconnecting
|
||||
// 3) packet failing to parse
|
||||
@@ -219,41 +219,88 @@ void RegisterThread(const std::string& str);
|
||||
|
||||
#endif // defined(DEBUG)
|
||||
|
||||
#define beammp_warn(x) Application::Console().Write(_this_location + std::string("[WARN] ") + (x))
|
||||
#define beammp_info(x) Application::Console().Write(_this_location + std::string("[INFO] ") + (x))
|
||||
#define beammp_error(x) \
|
||||
do { \
|
||||
Application::Console().Write(_this_location + std::string("[ERROR] ") + (x)); \
|
||||
Sentry.AddErrorBreadcrumb((x), _file_basename, _line); \
|
||||
#define beammp_internal_error(x) Application::Console().Write(_this_location + std::string("[INTERNAL ERROR] ") + (x))
|
||||
|
||||
#define beammp_warn(x) \
|
||||
do { \
|
||||
try{ \
|
||||
Application::Console().Write(_this_location + std::string("[WARN] ") + (x)); \
|
||||
} catch (const std::exception& e) { \
|
||||
beammp_internal_error(fmt::format("Exception in logging function, failed to print '{}': {}", #x, e.what()));\
|
||||
} \
|
||||
} while (false)
|
||||
#define beammp_lua_error(x) \
|
||||
do { \
|
||||
Application::Console().Write(_this_location + std::string("[LUA ERROR] ") + (x)); \
|
||||
#define beammp_info(x) \
|
||||
do { \
|
||||
try{ \
|
||||
Application::Console().Write(_this_location + std::string("[INFO] ") + (x)); \
|
||||
} catch (const std::exception& e) { \
|
||||
beammp_internal_error(fmt::format("Exception in logging function, failed to print '{}': {}", #x, e.what()));\
|
||||
} \
|
||||
} while (false)
|
||||
#define beammp_lua_warn(x) \
|
||||
do { \
|
||||
Application::Console().Write(_this_location + std::string("[LUA WARN] ") + (x)); \
|
||||
#define beammp_error(x) \
|
||||
do { \
|
||||
try{ \
|
||||
Application::Console().Write(_this_location + std::string("[ERROR] ") + (x)); \
|
||||
Sentry.AddErrorBreadcrumb((x), _file_basename, _line); \
|
||||
} catch (const std::exception& e) { \
|
||||
beammp_internal_error(fmt::format("Exception in logging function, failed to print '{}': {}", #x, e.what()));\
|
||||
} \
|
||||
} while (false)
|
||||
#define luaprint(x) Application::Console().Write(_this_location + std::string("[LUA] ") + (x))
|
||||
#define beammp_debug(x) \
|
||||
do { \
|
||||
if (Application::GetSettingBool("Debug")) { \
|
||||
Application::Console().Write(_this_location + std::string("[DEBUG] ") + (x)); \
|
||||
} \
|
||||
#define beammp_lua_error(x) \
|
||||
do { \
|
||||
try{ \
|
||||
Application::Console().Write(_this_location + std::string("[LUA ERROR] ") + (x)); \
|
||||
} catch (const std::exception& e) { \
|
||||
beammp_internal_error(fmt::format("Exception in logging function, failed to print '{}': {}", #x, e.what()));\
|
||||
} \
|
||||
} while (false)
|
||||
#define beammp_event(x) \
|
||||
do { \
|
||||
if (Application::GetSettingBool("Debug")) { \
|
||||
Application::Console().Write(_this_location + std::string("[EVENT] ") + (x)); \
|
||||
} \
|
||||
#define beammp_lua_warn(x) \
|
||||
do { \
|
||||
try{ \
|
||||
Application::Console().Write(_this_location + std::string("[LUA WARN] ") + (x)); \
|
||||
} catch (const std::exception& e) { \
|
||||
beammp_internal_error(fmt::format("Exception in logging function, failed to print '{}': {}", #x, e.what()));\
|
||||
} \
|
||||
} while (false)
|
||||
#define luaprint(x) \
|
||||
do { \
|
||||
try{ \
|
||||
Application::Console().Write(_this_location + std::string("[LUA] ") + (x)); \
|
||||
} catch (const std::exception& e) { \
|
||||
beammp_internal_error(fmt::format("Exception in logging function, failed to print '{}': {}", #x, e.what()));\
|
||||
} \
|
||||
} while (false)
|
||||
#define beammp_debug(x) \
|
||||
do { \
|
||||
try{ \
|
||||
if (Application::GetSettingBool("Debug")) { \
|
||||
Application::Console().Write(_this_location + std::string("[DEBUG] ") + (x)); \
|
||||
} \
|
||||
} catch (const std::exception& e) { \
|
||||
beammp_internal_error(fmt::format("Exception in logging function, failed to print '{}': {}", #x, e.what()));\
|
||||
} \
|
||||
} while (false)
|
||||
#define beammp_event(x) \
|
||||
do { \
|
||||
try{ \
|
||||
if (Application::GetSettingBool("Debug")) { \
|
||||
Application::Console().Write(_this_location + std::string("[EVENT] ") + (x)); \
|
||||
} \
|
||||
} catch (const std::exception& e) { \
|
||||
beammp_internal_error(fmt::format("Exception in logging function, failed to print '{}': {}", #x, e.what()));\
|
||||
} \
|
||||
} while (false)
|
||||
// trace() is a debug-build debug()
|
||||
#if defined(DEBUG)
|
||||
#define beammp_trace(x) \
|
||||
do { \
|
||||
if (Application::GetSettingBool("Debug")) { \
|
||||
Application::Console().Write(_this_location + std::string("[TRACE] ") + (x)); \
|
||||
} \
|
||||
#define beammp_trace(x) \
|
||||
do { \
|
||||
try{ \
|
||||
if (Application::GetSettingBool("Debug")) { \
|
||||
Application::Console().Write(_this_location + std::string("[TRACE] ") + (x)); \
|
||||
} \
|
||||
} catch (const std::exception& e) { \
|
||||
beammp_internal_error(fmt::format("Exception in logging function, failed to print '{}'", #x)); \
|
||||
} \
|
||||
} while (false)
|
||||
#else
|
||||
#define beammp_trace(x)
|
||||
|
||||
@@ -57,11 +57,11 @@ static std::optional<VehiclePacket> ParseVehiclePacket(const std::string& Packet
|
||||
|
||||
auto NameDataSep = withoutCode.find(':', 3);
|
||||
if (NameDataSep == std::string::npos) {
|
||||
// invalid packet
|
||||
beammp_debugf("Invalid packet from {} in ParseVehiclePacket: No ':' separator, assuming corrupted packet. Packet: '{}'", playerID, Packet);
|
||||
return std::nullopt;
|
||||
}
|
||||
if (NameDataSep + 1 > withoutCode.size()) {
|
||||
// invalid packet
|
||||
beammp_debugf("Invalid packet from {} in ParseVehiclePacket: Separator in unexpected place, assuming corrupted packet. Packet: '{}'", playerID, Packet);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ static std::optional<VehiclePacket> ParseVehiclePacket(const std::string& Packet
|
||||
return { { Data, PID, VID } }; // std::vector<char>(Data.begin(), Data.end())
|
||||
}
|
||||
}
|
||||
beammp_debugf("Failed to parse packet from player {}", playerID);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Application::Console().Internal().set_prompt("> ");
|
||||
|
||||
Application::SetSubsystemStatus("Main", Application::Status::Starting);
|
||||
|
||||
Reference in New Issue
Block a user