From ddf77a2d42f5251af04ae2b18501e12458ed6ec8 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Sun, 10 Dec 2023 16:54:53 +0000 Subject: [PATCH 1/2] fix: log fatal exceptions --- .../command/CommandHandlerCollection.cpp | 8 +++- .../controller/ActiveCallsignCollection.cpp | 24 ++++++++-- ...ControllerStatusEventHandlerCollection.cpp | 27 +++++++++-- .../HandoffEventHandlerCollection.cpp | 7 ++- .../RadarTargetEventHandlerCollection.cpp | 9 +++- .../FlightPlanEventHandlerCollection.cpp | 27 +++++++++-- .../IntentionCodeEventHandlerCollection.cpp | 7 ++- .../metar/MetarEventHandlerCollection.cpp | 7 ++- .../plugin/FunctionCallEventHandler.cpp | 32 +++++++++++-- src/plugin/plugin/UKPlugin.cpp | 6 ++- .../PrenoteMessageEventHandlerCollection.cpp | 28 ++++++++++-- .../push/PushEventProcessorCollection.cpp | 38 ++++++++++++++-- .../radarscreen/RadarRenderableCollection.cpp | 45 ++++++++++++++++--- .../timedevent/TimedEventCollection.cpp | 7 ++- .../EuroscopeThreadEventProcessor.cpp | 6 ++- src/utils/eventhandler/EventStream.tpp | 16 ++++++- src/utils/log/LoggerFunctions.cpp | 14 ++++++ src/utils/log/LoggerFunctions.h | 3 ++ 18 files changed, 271 insertions(+), 40 deletions(-) diff --git a/src/plugin/command/CommandHandlerCollection.cpp b/src/plugin/command/CommandHandlerCollection.cpp index b2d89966a..8c168675a 100644 --- a/src/plugin/command/CommandHandlerCollection.cpp +++ b/src/plugin/command/CommandHandlerCollection.cpp @@ -30,8 +30,12 @@ namespace UKControllerPlugin { for (std::vector>::const_iterator it = this->handlers.cbegin(); it != this->handlers.cend(); ++it) { - if ((*it)->ProcessCommand(command)) { - return true; + try { + if ((*it)->ProcessCommand(command)) { + return true; + } + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow("CommandHandlerCollection::ProcessCommand", typeid(*it).name(), e); } } diff --git a/src/plugin/controller/ActiveCallsignCollection.cpp b/src/plugin/controller/ActiveCallsignCollection.cpp index b38df4440..d07ebf97d 100644 --- a/src/plugin/controller/ActiveCallsignCollection.cpp +++ b/src/plugin/controller/ActiveCallsignCollection.cpp @@ -24,7 +24,11 @@ namespace UKControllerPlugin::Controller { this->activePositions[controller.GetNormalisedPosition().GetCallsign()].insert(controllerPtr).first; for (auto it = this->handlers.cbegin(); it != this->handlers.cend(); ++it) { - (*it)->ActiveCallsignAdded(controller); + try { + (*it)->ActiveCallsignAdded(controller); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow("ActiveCallsignCollection::AddCallsign", typeid(*it).name(), e); + } } } @@ -48,7 +52,11 @@ namespace UKControllerPlugin::Controller { this->userActive = true; for (auto it = this->handlers.cbegin(); it != this->handlers.cend(); ++it) { - (*it)->ActiveCallsignAdded(controller); + try { + (*it)->ActiveCallsignAdded(controller); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow("ActiveCallsignCollection::AddUserCallsign", typeid(*it).name(), e); + } } } @@ -69,7 +77,11 @@ namespace UKControllerPlugin::Controller { this->activePositions.clear(); this->userActive = false; for (auto it = this->handlers.cbegin(); it != this->handlers.cend(); ++it) { - (*it)->CallsignsFlushed(); + try { + (*it)->CallsignsFlushed(); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow("ActiveCallsignCollection::Flush", typeid(*it).name(), e); + } } } @@ -151,7 +163,11 @@ namespace UKControllerPlugin::Controller { this->activeCallsigns.erase(callsign); for (auto it = this->handlers.cbegin(); it != this->handlers.cend(); ++it) { - (*it)->ActiveCallsignRemoved(controller); + try { + (*it)->ActiveCallsignRemoved(controller); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow("ActiveCallsignCollection::RemoveCallsign", typeid(*it).name(), e); + } } } diff --git a/src/plugin/controller/ControllerStatusEventHandlerCollection.cpp b/src/plugin/controller/ControllerStatusEventHandlerCollection.cpp index 0a2722769..b1bf03732 100644 --- a/src/plugin/controller/ControllerStatusEventHandlerCollection.cpp +++ b/src/plugin/controller/ControllerStatusEventHandlerCollection.cpp @@ -18,7 +18,14 @@ namespace UKControllerPlugin { this->eventHandlers.begin(); it != this->eventHandlers.end(); ++it) { - (*it)->ControllerUpdateEvent(controller); + try { + (*it)->ControllerUpdateEvent(controller); + } catch (const std::exception& exception) { + LogFatalExceptionAndRethrow( + "ControllerStatusEventHandlerCollection::ControllerUpdateEvent", + std::string(typeid(*it).name()), + exception); + } } } @@ -32,7 +39,14 @@ namespace UKControllerPlugin { this->eventHandlers.begin(); it != this->eventHandlers.end(); ++it) { - (*it)->ControllerDisconnectEvent(controller); + try { + (*it)->ControllerDisconnectEvent(controller); + } catch (const std::exception& exception) { + LogFatalExceptionAndRethrow( + "ControllerStatusEventHandlerCollection::ControllerDisconnectEvent", + std::string(typeid(*it).name()), + exception); + } } } @@ -59,7 +73,14 @@ namespace UKControllerPlugin { this->eventHandlers.begin(); it != this->eventHandlers.end(); ++it) { - (*it)->SelfDisconnectEvent(); + try { + (*it)->SelfDisconnectEvent(); + } catch (const std::exception& exception) { + LogFatalExceptionAndRethrow( + "ControllerStatusEventHandlerCollection::SelfDisconnectEvent", + std::string(typeid(*it).name()), + exception); + } } } } // namespace Controller diff --git a/src/plugin/controller/HandoffEventHandlerCollection.cpp b/src/plugin/controller/HandoffEventHandlerCollection.cpp index 9566c70f9..2cdd1d67c 100644 --- a/src/plugin/controller/HandoffEventHandlerCollection.cpp +++ b/src/plugin/controller/HandoffEventHandlerCollection.cpp @@ -31,7 +31,12 @@ namespace UKControllerPlugin { EuroScopeCControllerInterface& targetController) const { for (auto it = this->eventHandlers.begin(); it != this->eventHandlers.end(); ++it) { - (*it)->HandoffInitiated(flightplan, transferringController, targetController); + try { + (*it)->HandoffInitiated(flightplan, transferringController, targetController); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "HandoffEventHandlerCollection::HandoffInitiated", typeid(*it).name(), e); + } } } } // namespace Controller diff --git a/src/plugin/euroscope/RadarTargetEventHandlerCollection.cpp b/src/plugin/euroscope/RadarTargetEventHandlerCollection.cpp index e3e0fc4e4..bb151ae3a 100644 --- a/src/plugin/euroscope/RadarTargetEventHandlerCollection.cpp +++ b/src/plugin/euroscope/RadarTargetEventHandlerCollection.cpp @@ -25,7 +25,14 @@ namespace UKControllerPlugin { this->handlerList.cbegin(); it != this->handlerList.cend(); ++it) { - (*it)->RadarTargetPositionUpdateEvent(radarTarget); + try { + (*it)->RadarTargetPositionUpdateEvent(radarTarget); + } catch (const std::exception& exception) { + LogFatalExceptionAndRethrow( + "RadarTargetEventHandlerCollection::RadarTargetEvent", + std::string(typeid(*it).name()), + exception); + } } } diff --git a/src/plugin/flightplan/FlightPlanEventHandlerCollection.cpp b/src/plugin/flightplan/FlightPlanEventHandlerCollection.cpp index 24084280f..6c45fb2dd 100644 --- a/src/plugin/flightplan/FlightPlanEventHandlerCollection.cpp +++ b/src/plugin/flightplan/FlightPlanEventHandlerCollection.cpp @@ -28,7 +28,14 @@ namespace UKControllerPlugin { this->handlerList.cbegin(); it != this->handlerList.cend(); ++it) { - (*it)->FlightPlanEvent(flightPlan, radarTarget); + try { + (*it)->FlightPlanEvent(flightPlan, radarTarget); + } catch (const std::exception& exception) { + LogFatalExceptionAndRethrow( + "FlightPlanEventHandlerCollection::FlightPlanEvent", + std::string(typeid(*it).name()), + exception); + } } } @@ -40,7 +47,14 @@ namespace UKControllerPlugin { this->handlerList.cbegin(); it != this->handlerList.cend(); ++it) { - (*it)->ControllerFlightPlanDataEvent(flightPlan, dataType); + try { + (*it)->ControllerFlightPlanDataEvent(flightPlan, dataType); + } catch (const std::exception& exception) { + LogFatalExceptionAndRethrow( + "FlightPlanEventHandlerCollection::ControllerFlightPlanDataEvent", + std::string(typeid(*it).name()), + exception); + } } } @@ -52,7 +66,14 @@ namespace UKControllerPlugin { this->handlerList.cbegin(); it != this->handlerList.cend(); ++it) { - (*it)->FlightPlanDisconnectEvent(flightPlan); + try { + (*it)->FlightPlanDisconnectEvent(flightPlan); + } catch (const std::exception& exception) { + LogFatalExceptionAndRethrow( + "FlightPlanEventHandlerCollection::FlightPlanDisconnectEvent", + std::string(typeid(*it).name()), + exception); + } } } diff --git a/src/plugin/intention/IntentionCodeEventHandlerCollection.cpp b/src/plugin/intention/IntentionCodeEventHandlerCollection.cpp index d57cbccb6..f766c3fc5 100644 --- a/src/plugin/intention/IntentionCodeEventHandlerCollection.cpp +++ b/src/plugin/intention/IntentionCodeEventHandlerCollection.cpp @@ -19,7 +19,12 @@ namespace UKControllerPlugin::IntentionCode { IntentionCodeEventHandlerCollection::IntentionCodeUpdated(const AircraftIntentionCode& aircraftIntentionCode) const { for (const auto& handler : eventHandlers) { - handler->IntentionCodeUpdated(aircraftIntentionCode); + try { + handler->IntentionCodeUpdated(aircraftIntentionCode); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "IntentionCodeEventHandlerCollection::IntentionCodeUpdated", typeid(handler).name(), e); + } } } } // namespace UKControllerPlugin::IntentionCode diff --git a/src/plugin/metar/MetarEventHandlerCollection.cpp b/src/plugin/metar/MetarEventHandlerCollection.cpp index 9ee1f4535..3fd0898ea 100644 --- a/src/plugin/metar/MetarEventHandlerCollection.cpp +++ b/src/plugin/metar/MetarEventHandlerCollection.cpp @@ -19,7 +19,12 @@ namespace UKControllerPlugin::Metar { void MetarEventHandlerCollection::UpdatedMetarEvent(const ParsedMetar& metar) const { for (const auto& handler : this->handlers) { - handler->MetarUpdated(metar); + try { + handler->MetarUpdated(metar); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "MetarEventHandlerCollection::UpdatedMetarEvent", typeid(handler).name(), e); + } } } diff --git a/src/plugin/plugin/FunctionCallEventHandler.cpp b/src/plugin/plugin/FunctionCallEventHandler.cpp index 3590259fd..77ab4b568 100644 --- a/src/plugin/plugin/FunctionCallEventHandler.cpp +++ b/src/plugin/plugin/FunctionCallEventHandler.cpp @@ -57,13 +57,25 @@ namespace UKControllerPlugin::Plugin { { auto callbackFunction = this->impl->callbackFunctions.find(functionId); if (callbackFunction != this->impl->callbackFunctions.cend()) { - callbackFunction->second.function(functionId, subject, area); + try { + callbackFunction->second.function(functionId, subject, area); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "FunctionCallEventHandler::CallFunction::Plugin::Callback", + callbackFunction->second.description, + e); + } return; } auto tagFunction = this->impl->tagFunctions.find(functionId); if (tagFunction != this->impl->tagFunctions.cend()) { - tagFunction->second.function(flightplan, radarTarget, subject, mousePos); + try { + tagFunction->second.function(flightplan, radarTarget, subject, mousePos); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "FunctionCallEventHandler::CallFunction::Plugin::Tag", tagFunction->second.description, e); + } return; } } @@ -79,13 +91,25 @@ namespace UKControllerPlugin::Plugin { { auto tagFunction = this->impl->radarScreenTagFunctions.find(functionId); if (tagFunction != this->impl->radarScreenTagFunctions.cend()) { - tagFunction->second.function(radarScreen, flightplan, radarTarget, subject, mousePos, area); + try { + tagFunction->second.function(radarScreen, flightplan, radarTarget, subject, mousePos, area); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "FunctionCallEventHandler::CallFunction::RadarScreen::Tag", tagFunction->second.description, e); + } return; } auto callbackFunction = this->impl->radarScreenCallbacks.find(functionId); if (callbackFunction != this->impl->radarScreenCallbacks.cend()) { - callbackFunction->second.function(functionId, radarScreen, subject, mousePos, area); + try { + callbackFunction->second.function(functionId, radarScreen, subject, mousePos, area); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "FunctionCallEventHandler::CallFunction::RadarScreen::Callback", + callbackFunction->second.description, + e); + } return; } } diff --git a/src/plugin/plugin/UKPlugin.cpp b/src/plugin/plugin/UKPlugin.cpp index 835b9af8b..7a4085be9 100644 --- a/src/plugin/plugin/UKPlugin.cpp +++ b/src/plugin/plugin/UKPlugin.cpp @@ -429,7 +429,11 @@ namespace UKControllerPlugin { TagData tagData( flightplanWrapper, radarTargetWrapper, ItemCode, dataAvailable, sItemString, pColorCode, pRGB, pFontSize); - this->tagEvents.TagItemUpdate(tagData); + try { + this->tagEvents.TagItemUpdate(tagData); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow("UKPlugin::OnGetTagItem::" + std::to_string(ItemCode), e); + } } /* diff --git a/src/plugin/prenote/PrenoteMessageEventHandlerCollection.cpp b/src/plugin/prenote/PrenoteMessageEventHandlerCollection.cpp index 67534ee4b..d3b252fce 100644 --- a/src/plugin/prenote/PrenoteMessageEventHandlerCollection.cpp +++ b/src/plugin/prenote/PrenoteMessageEventHandlerCollection.cpp @@ -12,28 +12,48 @@ namespace UKControllerPlugin::Prenote { void PrenoteMessageEventHandlerCollection::NewMessage(const PrenoteMessage& message) const { for (const auto& handler : handlers) { - handler->NewMessage(message); + try { + handler->NewMessage(message); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "PrenoteMessageEventHandlerCollection::NewMessage", typeid(handler).name(), e); + } } } void PrenoteMessageEventHandlerCollection::MessageCancelled(const PrenoteMessage& message) const { for (const auto& handler : handlers) { - handler->MessageCancelled(message); + try { + handler->MessageCancelled(message); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "PrenoteMessageEventHandlerCollection::MessageCancelled", typeid(handler).name(), e); + } } } void PrenoteMessageEventHandlerCollection::MessageAcknowledged(const PrenoteMessage& message) const { for (const auto& handler : handlers) { - handler->MessageAcknowledged(message); + try { + handler->MessageAcknowledged(message); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "PrenoteMessageEventHandlerCollection::MessageAcknowledged", typeid(handler).name(), e); + } } } void PrenoteMessageEventHandlerCollection::MessageTimeout(const PrenoteMessage& message) const { for (const auto& handler : handlers) { - handler->MessageTimeout(message); + try { + handler->MessageTimeout(message); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "PrenoteMessageEventHandlerCollection::MessageTimeout", typeid(handler).name(), e); + } } } diff --git a/src/plugin/push/PushEventProcessorCollection.cpp b/src/plugin/push/PushEventProcessorCollection.cpp index 9120d254a..7317e0391 100644 --- a/src/plugin/push/PushEventProcessorCollection.cpp +++ b/src/plugin/push/PushEventProcessorCollection.cpp @@ -90,7 +90,16 @@ namespace UKControllerPlugin { } calledProcessors.insert(*it); - (*it)->ProcessPushEvent(message); + + try { + (*it)->ProcessPushEvent(message); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "PushEventProcessorCollection::ProcessEvent::ByChannel::" + message.channel + + "::" + message.event, + typeid(*it).name(), + e); + } } } @@ -103,7 +112,16 @@ namespace UKControllerPlugin { } calledProcessors.insert(*it); - (*it)->ProcessPushEvent(message); + + try { + (*it)->ProcessPushEvent(message); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "PushEventProcessorCollection::ProcessEvent::ByEvent::" + message.channel + + "::" + message.event, + typeid(*it).name(), + e); + } } } @@ -114,7 +132,14 @@ namespace UKControllerPlugin { } calledProcessors.insert(*it); - (*it)->ProcessPushEvent(message); + try { + (*it)->ProcessPushEvent(message); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "PushEventProcessorCollection::ProcessEvent::All::" + message.channel + "::" + message.event, + typeid(*it).name(), + e); + } } } @@ -124,7 +149,12 @@ namespace UKControllerPlugin { void PushEventProcessorCollection::PluginEventsSynced() const { for (auto it = this->allEventProcessors.cbegin(); it != this->allEventProcessors.cend(); ++it) { - (*it)->PluginEventsSynced(); + try { + (*it)->PluginEventsSynced(); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "PushEventProcessorCollection::PluginEventsSynced", typeid(*it).name(), e); + } } } } // namespace Push diff --git a/src/plugin/radarscreen/RadarRenderableCollection.cpp b/src/plugin/radarscreen/RadarRenderableCollection.cpp index 127f4a0c5..5e6e9d6f9 100644 --- a/src/plugin/radarscreen/RadarRenderableCollection.cpp +++ b/src/plugin/radarscreen/RadarRenderableCollection.cpp @@ -72,8 +72,15 @@ namespace UKControllerPlugin { POINT mousePos, RECT itemArea) const { - this->allRenderers.at(this->screenObjectMap.at(objectId)) - ->LeftClick(radarScreen, objectId, objectDescription, mousePos, itemArea); + try { + this->allRenderers.at(this->screenObjectMap.at(objectId)) + ->LeftClick(radarScreen, objectId, objectDescription, mousePos, itemArea); + } catch (std::exception& e) { + LogFatalExceptionAndRethrow( + "RadarRenderableCollection::LeftClickScreenObject::" + std::to_string(objectId), + typeid(this->allRenderers.at(this->screenObjectMap.at(objectId))).name(), + e); + } } /* @@ -81,7 +88,14 @@ namespace UKControllerPlugin { */ void RadarRenderableCollection::MoveScreenObject(int objectId, std::string objectDes, RECT position) const { - this->allRenderers.at(this->screenObjectMap.at(objectId))->Move(position, objectDes); + try { + this->allRenderers.at(this->screenObjectMap.at(objectId))->Move(position, objectDes); + } catch (std::exception& e) { + LogFatalExceptionAndRethrow( + "RadarRenderableCollection::MoveScreenObject::" + std::to_string(objectId), + typeid(this->allRenderers.at(this->screenObjectMap.at(objectId))).name(), + e); + } } /* @@ -168,8 +182,15 @@ namespace UKControllerPlugin { std::string objectDescription, UKControllerPlugin::Euroscope::EuroscopeRadarLoopbackInterface& radarScreen) const { - this->allRenderers.at(this->screenObjectMap.at(objectId)) - ->RightClick(objectId, objectDescription, radarScreen); + try { + this->allRenderers.at(this->screenObjectMap.at(objectId)) + ->RightClick(objectId, objectDescription, radarScreen); + } catch (std::exception& e) { + LogFatalExceptionAndRethrow( + "RadarRenderableCollection::RightClickScreenObject::" + std::to_string(objectId), + typeid(this->allRenderers.at(this->screenObjectMap.at(objectId))).name(), + e); + } } /* @@ -182,7 +203,12 @@ namespace UKControllerPlugin { { for (std::vector::const_iterator it = group.cbegin(); it != group.cend(); ++it) { if (this->allRenderers.at(*it)->IsVisible()) { - this->allRenderers.at(*it)->Render(graphics, radarScreen); + try { + this->allRenderers.at(*it)->Render(graphics, radarScreen); + } catch (std::exception& e) { + LogFatalExceptionAndRethrow( + "RadarRenderableCollection::RenderGroup", typeid(this->allRenderers.at(*it)).name(), e); + } } } } @@ -196,7 +222,12 @@ namespace UKControllerPlugin { this->allRenderers.cbegin(); it != this->allRenderers.cend(); ++it) { - it->second->ResetPosition(); + try { + it->second->ResetPosition(); + } catch (std::exception& e) { + LogFatalExceptionAndRethrow( + "RadarRenderableCollection::ResetPosition", typeid(it->second).name(), e); + } } } } // namespace RadarScreen diff --git a/src/plugin/timedevent/TimedEventCollection.cpp b/src/plugin/timedevent/TimedEventCollection.cpp index a78c7c700..1459b70df 100644 --- a/src/plugin/timedevent/TimedEventCollection.cpp +++ b/src/plugin/timedevent/TimedEventCollection.cpp @@ -46,7 +46,12 @@ namespace UKControllerPlugin { for (std::vector>::const_iterator itVector = events.cbegin(); itVector != events.cend(); ++itVector) { - (*itVector)->TimedEventTrigger(); + try { + (*itVector)->TimedEventTrigger(); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "TimedEventCollection::Tick", std::string(typeid(*itVector).name()), e); + } } } } diff --git a/src/utils/eventhandler/EuroscopeThreadEventProcessor.cpp b/src/utils/eventhandler/EuroscopeThreadEventProcessor.cpp index 0ecbbb861..f620c4b06 100644 --- a/src/utils/eventhandler/EuroscopeThreadEventProcessor.cpp +++ b/src/utils/eventhandler/EuroscopeThreadEventProcessor.cpp @@ -28,7 +28,11 @@ namespace UKControllerPluginUtils::EventHandler { { auto guard = std::lock_guard(this->impl->mutex); while (!this->impl->eventQueue.empty()) { - this->impl->eventQueue.front()(); + try { + this->impl->eventQueue.front()(); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow("EuroscopeThreadEventProcessor::Drain", e); + } this->impl->eventQueue.pop(); } } diff --git a/src/utils/eventhandler/EventStream.tpp b/src/utils/eventhandler/EventStream.tpp index d84bfc172..9e88325b7 100644 --- a/src/utils/eventhandler/EventStream.tpp +++ b/src/utils/eventhandler/EventStream.tpp @@ -21,12 +21,24 @@ namespace UKControllerPluginUtils::EventHandler { { for (const auto& handler : this->handlers) { if ((handler.flags & EventHandlerFlags::Sync) == EventHandlerFlags::Sync) { - handler.handler->OnEvent(event); + try { + handler.handler->OnEvent(event); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "EventStream::OnEvent::Sync::" + std::string(typeid(T).name()), typeid(handler).name(), e); + } continue; } if ((handler.flags & EventHandlerFlags::Async) == EventHandlerFlags::Async) { - Async([event, handler]() { handler.handler->OnEvent(event); }); + Async([event, handler]() { + try { + handler.handler->OnEvent(event); + } catch (const std::exception& e) { + LogFatalExceptionAndRethrow( + "EventStream::OnEvent::Async::" + std::string(typeid(T).name()), typeid(handler).name(), e); + } + }); continue; } diff --git a/src/utils/log/LoggerFunctions.cpp b/src/utils/log/LoggerFunctions.cpp index c25b853bd..0230f8218 100644 --- a/src/utils/log/LoggerFunctions.cpp +++ b/src/utils/log/LoggerFunctions.cpp @@ -46,3 +46,17 @@ void ShutdownLogger(void) spdlog::drop_all(); logger.reset(); } + +void LogFatalExceptionAndRethrow(const std::string& source, const std::exception& exception) +{ + logger->critical( + "Critical exception of type " + std::string(typeid(exception).name()) + " at " + source + ": " + + exception.what()); + throw; +} + +void LogFatalExceptionAndRethrow( + const std::string& source, const std::string& subsource, const std::exception& exception) +{ + LogFatalExceptionAndRethrow(source + "::" + subsource, exception); +} diff --git a/src/utils/log/LoggerFunctions.h b/src/utils/log/LoggerFunctions.h index c0dc8aeea..bfc233180 100644 --- a/src/utils/log/LoggerFunctions.h +++ b/src/utils/log/LoggerFunctions.h @@ -4,6 +4,9 @@ namespace spdlog { class logger; } // namespace spdlog +void LogFatalExceptionAndRethrow(const std::string& source, const std::exception& exception); +void LogFatalExceptionAndRethrow( + const std::string& source, const std::string& subsource, const std::exception& exception); void LogCritical(std::string message); void LogDebug(std::string message); void LogError(std::string message); From 037adc6a95c7be452b1277703fb8a79264cc53eb Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Sun, 10 Dec 2023 16:56:57 +0000 Subject: [PATCH 2/2] fix: remove red herring log entry from integrations --- src/plugin/integration/IntegrationServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin/integration/IntegrationServer.cpp b/src/plugin/integration/IntegrationServer.cpp index 3fb891abf..5262bbb06 100644 --- a/src/plugin/integration/IntegrationServer.cpp +++ b/src/plugin/integration/IntegrationServer.cpp @@ -71,7 +71,7 @@ namespace UKControllerPlugin::Integration { while (this->acceptingConnections) { SOCKET integrationSocket = accept(this->serverSocket, nullptr, nullptr); if (integrationSocket == INVALID_SOCKET) { - if (!this->acceptingConnections) { + if (this->acceptingConnections) { LogError("Failed to accept integration server connection: " + std::to_string(WSAGetLastError())); } closesocket(integrationSocket);