From 4a50dabe1ab3f0af23f98221e8709f9512397247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=CA=9C=E1=B4=80=C9=B4?= Date: Mon, 9 Oct 2023 10:38:57 +0200 Subject: [PATCH] parseURI null check and error handling implemented (#710) * parseURI null check and error handling implemented * Cleaned and updated the changes according to restenb suggestion --- src/cosim/osp_config_parser.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index d613ae9e..b909f969 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -614,10 +614,18 @@ struct extended_model_description const auto xerces_cleanup = final_action([]() { xercesc::XMLPlatformUtils::Terminate(); }); + const auto domImpl = xercesc::DOMImplementationRegistry::getDOMImplementation(tc("LS").get()); const auto parser = static_cast(domImpl)->createLSParser(xercesc::DOMImplementationLS::MODE_SYNCHRONOUS, tc("http://www.w3.org/2001/XMLSchema").get()); + const auto doc = parser->parseURI(ospModelDescription.string().c_str()); - // TODO: Check return value for null + + if (doc == nullptr) { + std::ostringstream oss; + oss << "Validation of " << ospModelDescription.string() << " failed."; + BOOST_LOG_SEV(log::logger(), log::error) << oss.str(); + throw std::runtime_error(oss.str()); + } const auto rootElement = doc->getDocumentElement();