Skip to content

Commit

Permalink
added log message when ocpp config validation against schemas fails
Browse files Browse the repository at this point in the history
Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried committed Mar 2, 2023
1 parent 18918e0 commit 0a83821
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
Expand Down
8 changes: 7 additions & 1 deletion lib/ocpp/v16/charge_point_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand All @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion lib/ocpp/v201/device_model_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<boost::filesystem::path> available_schemas_paths;
Expand Down

0 comments on commit 0a83821

Please sign in to comment.