Included error message in TargetControllerErrorOccurred event
This commit is contained in:
@@ -12,7 +12,10 @@ namespace Bloom::Events
|
|||||||
static inline EventType type = EventType::TARGET_CONTROLLER_ERROR_OCCURRED;
|
static inline EventType type = EventType::TARGET_CONTROLLER_ERROR_OCCURRED;
|
||||||
static inline const std::string name = "TargetControllerErrorOccurred";
|
static inline const std::string name = "TargetControllerErrorOccurred";
|
||||||
|
|
||||||
|
std::string errorMessage;
|
||||||
|
|
||||||
TargetControllerErrorOccurred() = default;
|
TargetControllerErrorOccurred() = default;
|
||||||
|
TargetControllerErrorOccurred(const std::string& errorMessage): errorMessage(errorMessage) {};
|
||||||
|
|
||||||
[[nodiscard]] EventType getType() const override {
|
[[nodiscard]] EventType getType() const override {
|
||||||
return TargetControllerErrorOccurred::type;
|
return TargetControllerErrorOccurred::type;
|
||||||
|
|||||||
@@ -439,9 +439,10 @@ void TargetController::fireTargetEvents() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetController::emitErrorEvent(int correlationId) {
|
void TargetController::emitErrorEvent(int correlationId, const std::string& errorMessage) {
|
||||||
auto errorEvent = std::make_shared<Events::TargetControllerErrorOccurred>();
|
auto errorEvent = std::make_shared<Events::TargetControllerErrorOccurred>();
|
||||||
errorEvent->correlationId = correlationId;
|
errorEvent->correlationId = correlationId;
|
||||||
|
errorEvent->errorMessage = errorMessage;
|
||||||
this->eventManager.triggerEvent(errorEvent);
|
this->eventManager.triggerEvent(errorEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,7 +533,7 @@ void TargetController::onStepTargetExecutionEvent(const Events::StepTargetExecut
|
|||||||
|
|
||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to step execution on target - " + exception.getMessage());
|
Logger::error("Failed to step execution on target - " + exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,7 +554,7 @@ void TargetController::onResumeTargetExecutionEvent(const Events::ResumeTargetEx
|
|||||||
|
|
||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to resume execution on target - " + exception.getMessage());
|
Logger::error("Failed to resume execution on target - " + exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,7 +571,7 @@ void TargetController::onReadRegistersEvent(const Events::RetrieveRegistersFromT
|
|||||||
|
|
||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to read registers from target - " + exception.getMessage());
|
Logger::error("Failed to read registers from target - " + exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,7 +587,7 @@ void TargetController::onWriteRegistersEvent(const Events::WriteRegistersToTarge
|
|||||||
|
|
||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to write registers to target - " + exception.getMessage());
|
Logger::error("Failed to write registers to target - " + exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,7 +601,7 @@ void TargetController::onReadMemoryEvent(const Events::RetrieveMemoryFromTarget&
|
|||||||
|
|
||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to read memory from target - " + exception.getMessage());
|
Logger::error("Failed to read memory from target - " + exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,7 +657,7 @@ void TargetController::onWriteMemoryEvent(const Events::WriteMemoryToTarget& eve
|
|||||||
|
|
||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to write memory to target - " + exception.getMessage());
|
Logger::error("Failed to write memory to target - " + exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,7 +671,7 @@ void TargetController::onSetBreakpointEvent(const Events::SetBreakpointOnTarget&
|
|||||||
|
|
||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to set breakpoint on target - " + exception.getMessage());
|
Logger::error("Failed to set breakpoint on target - " + exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -684,7 +685,7 @@ void TargetController::onRemoveBreakpointEvent(const Events::RemoveBreakpointOnT
|
|||||||
|
|
||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to remove breakpoint on target - " + exception.getMessage());
|
Logger::error("Failed to remove breakpoint on target - " + exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,7 +705,7 @@ void TargetController::onSetProgramCounterEvent(const Events::SetProgramCounterO
|
|||||||
|
|
||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to set program counter on target - " + exception.getMessage());
|
Logger::error("Failed to set program counter on target - " + exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,7 +739,7 @@ void TargetController::onRetrieveTargetPinStatesEvent(const Events::RetrieveTarg
|
|||||||
|
|
||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to retrieve target pin states - " + exception.getMessage());
|
Logger::error("Failed to retrieve target pin states - " + exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -764,6 +765,6 @@ void TargetController::onSetPinStateEvent(const Events::SetTargetPinState& event
|
|||||||
} catch (const TargetOperationFailure& exception) {
|
} catch (const TargetOperationFailure& exception) {
|
||||||
Logger::error("Failed to set target pin state for pin " + event.pinDescriptor.name + " - "
|
Logger::error("Failed to set target pin state for pin " + event.pinDescriptor.name + " - "
|
||||||
+ exception.getMessage());
|
+ exception.getMessage());
|
||||||
this->emitErrorEvent(event.id);
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,8 +251,9 @@ namespace Bloom
|
|||||||
* a correlation ID matching the ID of the event that triggered the handler.
|
* a correlation ID matching the ID of the event that triggered the handler.
|
||||||
*
|
*
|
||||||
* @param correlationId
|
* @param correlationId
|
||||||
|
* @param errorMessage
|
||||||
*/
|
*/
|
||||||
void emitErrorEvent(int correlationId);
|
void emitErrorEvent(int correlationId, const std::string& errorMessage);
|
||||||
|
|
||||||
Targets::TargetDescriptor& getTargetDescriptor();
|
Targets::TargetDescriptor& getTargetDescriptor();
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ namespace Bloom
|
|||||||
const Events::SharedEventPointerNonConst<TriggerEventType> event,
|
const Events::SharedEventPointerNonConst<TriggerEventType> event,
|
||||||
std::optional<std::chrono::milliseconds> timeout = {}
|
std::optional<std::chrono::milliseconds> timeout = {}
|
||||||
) {
|
) {
|
||||||
|
using Bloom::Events::SharedEventPointer;
|
||||||
|
using Bloom::Events::TargetControllerErrorOccurred;
|
||||||
|
|
||||||
using ResponseEventType = typename TriggerEventType::TargetControllerResponseType;
|
using ResponseEventType = typename TriggerEventType::TargetControllerResponseType;
|
||||||
|
|
||||||
bool deRegisterEventType = false;
|
bool deRegisterEventType = false;
|
||||||
@@ -68,7 +71,7 @@ namespace Bloom
|
|||||||
|
|
||||||
auto responseEvent = this->eventListener.waitForEvent<
|
auto responseEvent = this->eventListener.waitForEvent<
|
||||||
ResponseEventType,
|
ResponseEventType,
|
||||||
Events::TargetControllerErrorOccurred
|
TargetControllerErrorOccurred
|
||||||
>(timeout.value_or(this->defaultTimeout), event->id);
|
>(timeout.value_or(this->defaultTimeout), event->id);
|
||||||
|
|
||||||
if (deRegisterEventType) {
|
if (deRegisterEventType) {
|
||||||
@@ -79,11 +82,17 @@ namespace Bloom
|
|||||||
throw Bloom::Exceptions::Exception("Timed out waiting for response from TargetController.");
|
throw Bloom::Exceptions::Exception("Timed out waiting for response from TargetController.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!std::holds_alternative<Events::SharedEventPointer<ResponseEventType>>(responseEvent.value())) {
|
if (!std::holds_alternative<SharedEventPointer<ResponseEventType>>(responseEvent.value())) {
|
||||||
|
if (std::holds_alternative<SharedEventPointer<TargetControllerErrorOccurred>>(responseEvent.value())) {
|
||||||
|
auto& tcErrorEvent = std::get<SharedEventPointer<TargetControllerErrorOccurred>>(responseEvent.value());
|
||||||
|
throw Bloom::Exceptions::Exception(tcErrorEvent->errorMessage);
|
||||||
|
|
||||||
|
} else {
|
||||||
throw Bloom::Exceptions::Exception("Unexpected response from TargetController");
|
throw Bloom::Exceptions::Exception("Unexpected response from TargetController");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return std::get<Events::SharedEventPointer<ResponseEventType>>(responseEvent.value());
|
return std::get<SharedEventPointer<ResponseEventType>>(responseEvent.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user