mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-25 21:40:09 +00:00
handle all exceptions which happen inside a logging macro
and print them ;)
This commit is contained in:
3 files changed
+80
-32
No files matched your search
+76
-29
@@ -150,7 +150,7 @@ public:
|
|||||||
|
|
||||||
// Keeps track of how many packets we dropped on UDP due to fundamentally being malformed
|
// Keeps track of how many packets we dropped on UDP due to fundamentally being malformed
|
||||||
static inline std::atomic_size_t MalformedUdpPackets { 0 };
|
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
|
// 1) not having a valid (known) player id
|
||||||
// 2) player disconnecting
|
// 2) player disconnecting
|
||||||
// 3) packet failing to parse
|
// 3) packet failing to parse
|
||||||
@@ -219,41 +219,88 @@ void RegisterThread(const std::string& str);
|
|||||||
|
|
||||||
#endif // defined(DEBUG)
|
#endif // defined(DEBUG)
|
||||||
|
|
||||||
#define beammp_warn(x) Application::Console().Write(_this_location + std::string("[WARN] ") + (x))
|
#define beammp_internal_error(x) Application::Console().Write(_this_location + std::string("[INTERNAL ERROR] ") + (x))
|
||||||
#define beammp_info(x) Application::Console().Write(_this_location + std::string("[INFO] ") + (x))
|
|
||||||
#define beammp_error(x) \
|
#define beammp_warn(x) \
|
||||||
do { \
|
do { \
|
||||||
Application::Console().Write(_this_location + std::string("[ERROR] ") + (x)); \
|
try{ \
|
||||||
Sentry.AddErrorBreadcrumb((x), _file_basename, _line); \
|
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)
|
} while (false)
|
||||||
#define beammp_lua_error(x) \
|
#define beammp_info(x) \
|
||||||
do { \
|
do { \
|
||||||
Application::Console().Write(_this_location + std::string("[LUA ERROR] ") + (x)); \
|
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)
|
} while (false)
|
||||||
#define beammp_lua_warn(x) \
|
#define beammp_error(x) \
|
||||||
do { \
|
do { \
|
||||||
Application::Console().Write(_this_location + std::string("[LUA WARN] ") + (x)); \
|
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)
|
} while (false)
|
||||||
#define luaprint(x) Application::Console().Write(_this_location + std::string("[LUA] ") + (x))
|
#define beammp_lua_error(x) \
|
||||||
#define beammp_debug(x) \
|
do { \
|
||||||
do { \
|
try{ \
|
||||||
if (Application::GetSettingBool("Debug")) { \
|
Application::Console().Write(_this_location + std::string("[LUA ERROR] ") + (x)); \
|
||||||
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)
|
} while (false)
|
||||||
#define beammp_event(x) \
|
#define beammp_lua_warn(x) \
|
||||||
do { \
|
do { \
|
||||||
if (Application::GetSettingBool("Debug")) { \
|
try{ \
|
||||||
Application::Console().Write(_this_location + std::string("[EVENT] ") + (x)); \
|
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)
|
} while (false)
|
||||||
// trace() is a debug-build debug()
|
// trace() is a debug-build debug()
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
#define beammp_trace(x) \
|
#define beammp_trace(x) \
|
||||||
do { \
|
do { \
|
||||||
if (Application::GetSettingBool("Debug")) { \
|
try{ \
|
||||||
Application::Console().Write(_this_location + std::string("[TRACE] ") + (x)); \
|
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)
|
} while (false)
|
||||||
#else
|
#else
|
||||||
#define beammp_trace(x)
|
#define beammp_trace(x)
|
||||||
|
|||||||
+3
-2
@@ -57,11 +57,11 @@ static std::optional<VehiclePacket> ParseVehiclePacket(const std::string& Packet
|
|||||||
|
|
||||||
auto NameDataSep = withoutCode.find(':', 3);
|
auto NameDataSep = withoutCode.find(':', 3);
|
||||||
if (NameDataSep == std::string::npos) {
|
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;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
if (NameDataSep + 1 > withoutCode.size()) {
|
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;
|
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())
|
return { { Data, PID, VID } }; // std::vector<char>(Data.begin(), Data.end())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
beammp_debugf("Failed to parse packet from player {}", playerID);
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -111,7 +111,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::Console().Internal().set_prompt("> ");
|
Application::Console().Internal().set_prompt("> ");
|
||||||
|
|
||||||
Application::SetSubsystemStatus("Main", Application::Status::Starting);
|
Application::SetSubsystemStatus("Main", Application::Status::Starting);
|
||||||
|
|||||||
Reference in new issue
Block a user