Skip to content

Commit

Permalink
add error handling for read system and libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Dec 30, 2024
1 parent 00183c4 commit 559f739
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
13 changes: 2 additions & 11 deletions src/solver/modeler/loadFiles/readLibraries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,12 @@ static Study::SystemModel::Library loadSingleLibrary(const fs::path& filePath)
}
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();

handleYamlError(e, filePath);
throw ErrorLoadingYaml(e.what());
}
catch (const std::runtime_error& e)
{
logs.error() << "Error while parsing or converting this library yaml file:";
logs.error() << filePath;
logs.error() << e.what();

handleRuntimeError(e, filePath);
throw ErrorLoadingYaml(e.what());
}
}
Expand Down
15 changes: 4 additions & 11 deletions src/solver/modeler/loadFiles/readSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,23 @@ namespace Antares::Solver::LoadFiles
Study::SystemModel::System loadSystem(const fs::path& studyPath,
const std::vector<Study::SystemModel::Library>& libraries)
{
std::string filename = "system.yml";
try
{
const std::string systemStr = IO::readFile(studyPath / "input" / "system.yml");
const std::string systemStr = IO::readFile(studyPath / "input" / filename);
SystemParser::Parser parser;
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();

handleYamlError(e, filename);
throw ErrorLoadingYaml(e.what());
}
catch (const std::runtime_error& e)
{
logs.error() << "Error while parsing or converting the system file:";
logs.error() << e.what();

handleRuntimeError(e, filename);
throw ErrorLoadingYaml(e.what());
}
}
Expand Down

0 comments on commit 559f739

Please sign in to comment.