From 282086eaa2d8dbeeb0d8f26a2c0284f80a3bd229 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 23 Nov 2024 21:09:33 +0000 Subject: [PATCH] Tidied exceptions --- src/DebugServer/Gdb/GdbRspDebugServer.hpp | 9 +++++++++ src/Exceptions/FatalErrorException.hpp | 14 ++++++++++++++ src/Exceptions/InternalFatalErrorException.hpp | 6 +++--- src/Exceptions/InvalidConfig.hpp | 6 +++--- src/Exceptions/TargetControllerStartupFailure.hpp | 6 +++--- src/TargetController/Exceptions/DeviceFailure.hpp | 6 +++--- src/TargetController/Exceptions/DeviceNotFound.hpp | 4 ++-- src/TargetController/TargetControllerComponent.cpp | 5 +++-- 8 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 src/Exceptions/FatalErrorException.hpp diff --git a/src/DebugServer/Gdb/GdbRspDebugServer.hpp b/src/DebugServer/Gdb/GdbRspDebugServer.hpp index 0c95955d..e0376247 100644 --- a/src/DebugServer/Gdb/GdbRspDebugServer.hpp +++ b/src/DebugServer/Gdb/GdbRspDebugServer.hpp @@ -69,6 +69,7 @@ #include "Exceptions/DebugServerInterrupted.hpp" #include "src/Exceptions/Exception.hpp" +#include "src/Exceptions/FatalErrorException.hpp" #include "src/Exceptions/InvalidConfig.hpp" namespace DebugServer::Gdb @@ -288,6 +289,10 @@ namespace DebugServer::Gdb // Server was interrupted by an event Logger::debug("GDB RSP interrupted"); return; + + } catch (const ::Exceptions::FatalErrorException& exception) { + this->endDebugSession(); + throw exception; } } @@ -547,6 +552,10 @@ namespace DebugServer::Gdb Logger::debug("GDB RSP interrupted"); return; + } catch (const ::Exceptions::FatalErrorException& exception) { + this->endDebugSession(); + throw exception; + } catch (const ::Exceptions::Exception& exception) { Logger::error("Failed to handle target execution state changed event - " + exception.getMessage()); } diff --git a/src/Exceptions/FatalErrorException.hpp b/src/Exceptions/FatalErrorException.hpp new file mode 100644 index 00000000..9ab55635 --- /dev/null +++ b/src/Exceptions/FatalErrorException.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "Exception.hpp" + +namespace Exceptions +{ + class FatalErrorException: public Exception + { + public: + explicit FatalErrorException(const std::string& message) + : Exception(message) + {} + }; +} diff --git a/src/Exceptions/InternalFatalErrorException.hpp b/src/Exceptions/InternalFatalErrorException.hpp index 7492f7df..3425069a 100644 --- a/src/Exceptions/InternalFatalErrorException.hpp +++ b/src/Exceptions/InternalFatalErrorException.hpp @@ -1,15 +1,15 @@ #pragma once -#include "Exception.hpp" +#include "FatalErrorException.hpp" #include "src/Services/PathService.hpp" namespace Exceptions { - class InternalFatalErrorException: public Exception + class InternalFatalErrorException: public FatalErrorException { public: explicit InternalFatalErrorException(const std::string& message) - : Exception( + : FatalErrorException( "Internal fatal error - " + message + " - please report this via " + Services::PathService::homeDomainName() + "/report-issue" ) diff --git a/src/Exceptions/InvalidConfig.hpp b/src/Exceptions/InvalidConfig.hpp index f9962fc9..f111cb67 100644 --- a/src/Exceptions/InvalidConfig.hpp +++ b/src/Exceptions/InvalidConfig.hpp @@ -1,14 +1,14 @@ #pragma once -#include "Exception.hpp" +#include "FatalErrorException.hpp" namespace Exceptions { - class InvalidConfig: public Exception + class InvalidConfig: public FatalErrorException { public: explicit InvalidConfig(const std::string& message) - : Exception(message) + : FatalErrorException(message) {} }; } diff --git a/src/Exceptions/TargetControllerStartupFailure.hpp b/src/Exceptions/TargetControllerStartupFailure.hpp index 6010ac62..8549b244 100644 --- a/src/Exceptions/TargetControllerStartupFailure.hpp +++ b/src/Exceptions/TargetControllerStartupFailure.hpp @@ -1,14 +1,14 @@ #pragma once -#include "Exception.hpp" +#include "FatalErrorException.hpp" namespace Exceptions { - class TargetControllerStartupFailure: public Exception + class TargetControllerStartupFailure: public FatalErrorException { public: explicit TargetControllerStartupFailure(const std::string& message) - : Exception(message) + : FatalErrorException(message) {} }; } diff --git a/src/TargetController/Exceptions/DeviceFailure.hpp b/src/TargetController/Exceptions/DeviceFailure.hpp index 91c46941..25babb10 100644 --- a/src/TargetController/Exceptions/DeviceFailure.hpp +++ b/src/TargetController/Exceptions/DeviceFailure.hpp @@ -1,14 +1,14 @@ #pragma once -#include "src/Exceptions/Exception.hpp" +#include "src/Exceptions/FatalErrorException.hpp" namespace Exceptions { - class DeviceFailure: public Exception + class DeviceFailure: public FatalErrorException { public: explicit DeviceFailure(const std::string& message) - : Exception(message) + : FatalErrorException(message) {} }; } diff --git a/src/TargetController/Exceptions/DeviceNotFound.hpp b/src/TargetController/Exceptions/DeviceNotFound.hpp index a4ccda7c..2b70c044 100644 --- a/src/TargetController/Exceptions/DeviceNotFound.hpp +++ b/src/TargetController/Exceptions/DeviceNotFound.hpp @@ -4,11 +4,11 @@ namespace Exceptions { - class DeviceNotFound: public Exception + class DeviceNotFound: public FatalErrorException { public: explicit DeviceNotFound(const std::string& message) - : Exception(message) + : FatalErrorException(message) {} }; } diff --git a/src/TargetController/TargetControllerComponent.cpp b/src/TargetController/TargetControllerComponent.cpp index f7f58064..2562f7dc 100644 --- a/src/TargetController/TargetControllerComponent.cpp +++ b/src/TargetController/TargetControllerComponent.cpp @@ -15,6 +15,7 @@ #include "src/Services/StringService.hpp" #include "src/Logger/Logger.hpp" +#include "src/Exceptions/FatalErrorException.hpp" #include "src/Exceptions/InvalidConfig.hpp" namespace TargetController @@ -78,7 +79,7 @@ namespace TargetController while (this->getThreadState() == ThreadState::READY) { this->refreshExecutionState(); - TargetControllerComponent::notifier.waitForNotification(std::chrono::milliseconds(60)); + TargetControllerComponent::notifier.waitForNotification(std::chrono::milliseconds(60 )); this->processQueuedCommands(); this->eventListener->dispatchCurrentEvents(); @@ -455,7 +456,7 @@ namespace TargetController this->registerCommandResponse(commandId, commandHandlerIt->second(*(command.get()))); - } catch (const DeviceFailure& exception) { + } catch (const FatalErrorException& exception) { this->registerCommandResponse( commandId, std::make_unique(exception.getMessage())