Skip to content

Commit

Permalink
Merge pull request #550 from AndyTWF/fatal-exception-logging
Browse files Browse the repository at this point in the history
Fatal exception logging
  • Loading branch information
AndyTWF authored Dec 10, 2023
2 parents 6001c77 + 037adc6 commit b0e1985
Show file tree
Hide file tree
Showing 19 changed files with 272 additions and 41 deletions.
8 changes: 6 additions & 2 deletions src/plugin/command/CommandHandlerCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ namespace UKControllerPlugin {
for (std::vector<std::shared_ptr<CommandHandlerInterface>>::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);
}
}

Expand Down
24 changes: 20 additions & 4 deletions src/plugin/controller/ActiveCallsignCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand All @@ -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);
}
}
}

Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down
27 changes: 24 additions & 3 deletions src/plugin/controller/ControllerStatusEventHandlerCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand All @@ -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);
}
}
}

Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/plugin/controller/HandoffEventHandlerCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/plugin/euroscope/RadarTargetEventHandlerCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
27 changes: 24 additions & 3 deletions src/plugin/flightplan/FlightPlanEventHandlerCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand All @@ -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);
}
}
}

Expand All @@ -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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugin/integration/IntegrationServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/plugin/intention/IntentionCodeEventHandlerCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion src/plugin/metar/MetarEventHandlerCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
32 changes: 28 additions & 4 deletions src/plugin/plugin/FunctionCallEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/plugin/plugin/UKPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/*
Expand Down
28 changes: 24 additions & 4 deletions src/plugin/prenote/PrenoteMessageEventHandlerCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
Loading

0 comments on commit b0e1985

Please sign in to comment.