diff --git a/src/solver/modeler/loadFiles/readLibraries.cpp b/src/solver/modeler/loadFiles/readLibraries.cpp index dec3433b47..df9f2235ec 100644 --- a/src/solver/modeler/loadFiles/readLibraries.cpp +++ b/src/solver/modeler/loadFiles/readLibraries.cpp @@ -43,7 +43,7 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath) } catch (const std::runtime_error& e) { - logs.error() << "Error while parsing or converting this yaml file:"; + logs.error() << "Error while parsing or converting this library yaml file:"; logs.error() << filePath; logs.error() << e.what(); diff --git a/src/solver/modeler/loadFiles/readSystem.cpp b/src/solver/modeler/loadFiles/readSystem.cpp index 187213b917..02872ff635 100644 --- a/src/solver/modeler/loadFiles/readSystem.cpp +++ b/src/solver/modeler/loadFiles/readSystem.cpp @@ -20,6 +20,7 @@ */ #include +#include #include #include #include "antares/solver/modeler/loadFiles/loadFiles.h" @@ -33,12 +34,20 @@ Study::SystemModel::System loadSystem(const fs::path& studyPath, const std::vector& libraries) { const std::string systemStr = IO::readFile(studyPath / "input" / "system.yml"); - SystemParser::Parser parser; - // Add try/catch and error handling - SystemParser::System systemObj = parser.parse(systemStr); - return SystemConverter::convert(systemObj, libraries); + try + { + SystemParser::System systemObj = parser.parse(systemStr); + return SystemConverter::convert(systemObj, libraries); + } + catch (const std::runtime_error& e) + { + logs.error() << "Error while parsing or converting the system file:"; + logs.error() << e.what(); + + throw std::runtime_error(e.what()); + } } } // namespace Antares::Solver::LoadFiles diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index 8f7ded731c..d3ce837f63 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -166,4 +166,30 @@ BOOST_FIXTURE_TEST_CASE(read_system_file, FixtureLoadFile) auto system = Antares::Solver::LoadFiles::loadSystem(studyPath, libraries); } +BOOST_FIXTURE_TEST_CASE(read_invalid_system_file, FixtureLoadFile) +{ + std::ofstream libStream(libraryDirPath / "simple.yml"); + libStream << R"( + library: + id: std + description: lib_description + port-types: [] + models: + - id: generator + description: A basic generator model + + )"; + libStream.close(); + + std::ofstream systemStream(inputPath / "system.yml"); + systemStream << R"( + system: + )"; + systemStream.close(); + + auto libraries = Antares::Solver::LoadFiles::loadLibraries(studyPath); + BOOST_CHECK_THROW(Antares::Solver::LoadFiles::loadSystem(studyPath, libraries), + std::runtime_error); +} + BOOST_AUTO_TEST_SUITE_END()