From 254dfbb5ea72e6472e2ebe741c1137899fc8186f Mon Sep 17 00:00:00 2001 From: TWF0dGhpYXMtTklERUM <155968231+Matthias-NIDEC@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:03:00 +0100 Subject: [PATCH] Harden message_callback against runtime error (#884) * Harden message_callback against runtime error --------- Signed-off-by: Matthias Suess --- lib/ocpp/v16/charge_point_impl.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index 3f1399590..e153d0d44 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -1263,10 +1263,15 @@ void ChargePointImpl::message_callback(const std::string& message) { EVLOG_error << "Exception during handling of message: " << e.what(); this->message_dispatcher->dispatch_call_error( CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}))); + return; } catch (const json::exception& e) { EVLOG_error << "JSON exception during reception of message: " << e.what(); this->message_dispatcher->dispatch_call_error(CallError(MessageId("-1"), "GenericError", e.what(), json({}))); return; + } catch (const std::runtime_error& e) { + EVLOG_error << "runtime_error during reception of message: " << e.what(); + this->message_dispatcher->dispatch_call_error(CallError(MessageId("-1"), "GenericError", e.what(), json({}))); + return; } auto json_message = enhanced_message.message;