Skip to content

Commit

Permalink
catch yaml exception, use mark if available
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Dec 23, 2024
1 parent f8c3d70 commit 9d93c9d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/solver/modeler/loadFiles/readLibraries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#include <yaml-cpp/yaml.h>

#include <antares/io/file.h>
#include <antares/logs/logs.h>
#include <antares/solver/modelConverter/modelConverter.h>
Expand All @@ -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:";
Expand Down
13 changes: 13 additions & 0 deletions src/solver/modeler/loadFiles/readSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#include <yaml-cpp/yaml.h>

#include <antares/io/file.h>
#include <antares/logs/logs.h>
#include <antares/solver/systemParser/converter.h>
Expand All @@ -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:";
Expand Down
14 changes: 11 additions & 3 deletions src/solver/modeler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 9d93c9d

Please sign in to comment.