From 9d93c9d73b62a1df80ab4e6191bd1690e4141596 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 23 Dec 2024 14:38:23 +0100 Subject: [PATCH] catch yaml exception, use mark if available --- src/solver/modeler/loadFiles/readLibraries.cpp | 14 +++++++++++++- src/solver/modeler/loadFiles/readSystem.cpp | 13 +++++++++++++ src/solver/modeler/main.cpp | 14 +++++++++++--- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index df9f2235ec..fb286270c4 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -19,6 +19,8 @@ * along with Antares_Simulator. If not, see . */ +#include + #include #include #include @@ -35,12 +37,22 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) const std::string libraryStr = IO::readFile(filePath); ModelParser::Parser parser; - try { ModelParser::Library libraryObj = parser.parse(libraryStr); return ModelConverter::convert(libraryObj); } + catch (const YAML::Exception& e) + { + logs.error() << "Error while parsing this library yaml file: " << filePath; + if (!e.mark.is_null()) + { + logs.error() << "Line " << e.mark.line << " column " << e.mark.column; + } + logs.error() << e.what(); + + throw std::runtime_error(e.what()); + } catch (const std::runtime_error& e) { logs.error() << "Error while parsing or converting this library yaml file:"; diff --git a/src/solver/modeler/loadFiles/readSystem.cpp b/src/solver/modeler/loadFiles/readSystem.cpp index 02872ff635..6b2d8d05ab 100644 --- a/src/solver/modeler/loadFiles/readSystem.cpp +++ b/src/solver/modeler/loadFiles/readSystem.cpp @@ -19,6 +19,8 @@ * along with Antares_Simulator. If not, see . */ +#include + #include #include #include @@ -41,6 +43,17 @@ Study::SystemModel::System loadSystem(const fs::path& studyPath, SystemParser::System systemObj = parser.parse(systemStr); return SystemConverter::convert(systemObj, libraries); } + catch (const YAML::Exception& e) + { + logs.error() << "Error while parsing the yaml system file"; + if (!e.mark.is_null()) + { + logs.error() << "Line " << e.mark.line << " column " << e.mark.column; + } + logs.error() << e.what(); + + throw std::runtime_error(e.what()); + } catch (const std::runtime_error& e) { logs.error() << "Error while parsing or converting the system file:"; diff --git a/src/solver/modeler/main.cpp b/src/solver/modeler/main.cpp index ac28dbf124..e0e3ec1823 100644 --- a/src/solver/modeler/main.cpp +++ b/src/solver/modeler/main.cpp @@ -43,9 +43,17 @@ int main(int argc, const char** argv) return EXIT_FAILURE; } - const auto parameters = LoadFiles::parseModelerParameters(studyPath); - const auto libraries = LoadFiles::loadLibraries(studyPath); - const auto system = LoadFiles::loadSystem(studyPath, libraries); + try + { + const auto parameters = LoadFiles::parseModelerParameters(studyPath); + const auto libraries = LoadFiles::loadLibraries(studyPath); + const auto system = LoadFiles::loadSystem(studyPath, libraries); + } + catch (...) + { + logs.error() << "Error while loading files, exiting"; + return EXIT_FAILURE; + } return 0; }