From 0a8382181aab2b7a5efe2ec06b24ef6e2809575f Mon Sep 17 00:00:00 2001 From: pietfried Date: Wed, 1 Mar 2023 14:38:20 +0100 Subject: [PATCH] added log message when ocpp config validation against schemas fails Signed-off-by: pietfried --- CMakeLists.txt | 2 +- lib/ocpp/v16/charge_point_configuration.cpp | 8 +++++++- lib/ocpp/v201/device_model_management.cpp | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6d099b34..848f530ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.14) project(ocpp - VERSION 0.5.1 + VERSION 0.5.2 DESCRIPTION "A C++ implementation of the Open Charge Point Protocol" LANGUAGES CXX ) diff --git a/lib/ocpp/v16/charge_point_configuration.cpp b/lib/ocpp/v16/charge_point_configuration.cpp index a0240d658..db710f438 100644 --- a/lib/ocpp/v16/charge_point_configuration.cpp +++ b/lib/ocpp/v16/charge_point_configuration.cpp @@ -28,7 +28,9 @@ ChargePointConfiguration::ChargePointConfiguration(const json& config, const std // validate config entries Schemas schemas = Schemas(boost::filesystem::path(ocpp_main_path) / "profile_schemas"); - auto patch = schemas.get_validator()->validate(config); + + try { + auto patch = schemas.get_validator()->validate(config); if (patch.is_null()) { // no defaults substituted EVLOG_debug << "Using a charge point configuration without default values."; @@ -39,6 +41,10 @@ ChargePointConfiguration::ChargePointConfiguration(const json& config, const std auto patched_config = config.patch(patch); this->config = patched_config; } + } catch (const std::exception &e) { + EVLOG_error << "Error while validating OCPP config against schemas: " << e.what(); + EVLOG_AND_THROW(e); + } if (!this->config["Core"].contains("SupportedFeatureProfiles")) { throw std::runtime_error("SupportedFeatureProfiles key is missing from config"); diff --git a/lib/ocpp/v201/device_model_management.cpp b/lib/ocpp/v201/device_model_management.cpp index d41f792d7..392b5991b 100644 --- a/lib/ocpp/v201/device_model_management.cpp +++ b/lib/ocpp/v201/device_model_management.cpp @@ -186,7 +186,8 @@ DeviceModelManager::DeviceModelManager(const json& config, const std::string& oc json_config = json_config.patch(patch); } } catch (const std::exception& e) { - EVLOG_error << "Validation failed, here is why: " << e.what() << "\n"; + EVLOG_error << "Error while validating OCPP config against schemas: " << e.what(); + EVLOG_AND_THROW(e); } std::set available_schemas_paths;