diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index d94effd421..73d3a611f5 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -107,12 +107,13 @@ static void loadHours(const std::string& hoursStr, AdditionalConstraints& additi } } -static void readRHS(AdditionalConstraints& additionalConstraints, - const fs::path& parentPath) +static bool readRHS(AdditionalConstraints& additionalConstraints, + const fs::path& rhsPath) { - loadFile(parentPath / ("rhs_" + additionalConstraints.name + ".txt"), - additionalConstraints.rhs); - fillIfEmpty(additionalConstraints.rhs, 0.0); + const auto ret = loadFile(rhsPath, + additionalConstraints.rhs); + if (ret) { fillIfEmpty(additionalConstraints.rhs, 0.0); } + return ret; } bool STStorageInput::loadAdditionalConstraints(const fs::path& parentPath) @@ -154,7 +155,13 @@ bool STStorageInput::loadAdditionalConstraints(const fs::path& parentPath) } } - readRHS(additionalConstraints, parentPath); + if (const auto rhsPath = parentPath / ( + "rhs_" + additionalConstraints.name + + ".txt"); !readRHS(additionalConstraints, rhsPath)) + { + logs.error() << "Error while reading rhs file: " << rhsPath; + return false; + } if (auto [ok, error_msg] = additionalConstraints.validate(); !ok) { logs.error() << "Invalid constraint in section: " << section->name; diff --git a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp index f5d3de3eef..67a6fc7d52 100644 --- a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp +++ b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp @@ -804,7 +804,7 @@ BOOST_AUTO_TEST_CASE(loadAdditionalConstraints_MalformedRhsFile) std::ofstream iniFile(testPath / "additional-constraints.ini"); iniFile << "[constraint1]\n"; - iniFile << "cluster=ClusterA\n"; + iniFile << "cluster=cluster1\n"; iniFile << "variable=injection\n"; iniFile << "operator=less\n"; iniFile << "hours=[1,2,3]\n"; @@ -816,12 +816,14 @@ BOOST_AUTO_TEST_CASE(loadAdditionalConstraints_MalformedRhsFile) ShortTermStorage::STStorageInput storageInput; ShortTermStorage::STStorageCluster cluster; - cluster.id = "ClusterA"; + cluster.id = "cluster1"; storageInput.storagesByIndex.push_back(cluster); bool result = storageInput.loadAdditionalConstraints(testPath); BOOST_CHECK_EQUAL(result, false); - + /*"Error while reading rhs file: " << "rhs_" << additionalConstraints.name + << + ".txt";*/ std::filesystem::remove_all(testPath); } @@ -832,7 +834,7 @@ BOOST_AUTO_TEST_CASE(loadAdditionalConstraints_IncompleteRhsFile) std::ofstream iniFile(testPath / "additional-constraints.ini"); iniFile << "[constraint1]\n"; - iniFile << "cluster=ClusterA\n"; + iniFile << "cluster=cluster1\n"; iniFile << "variable=injection\n"; iniFile << "operator=less\n"; iniFile << "hours=[1,2,3]\n"; @@ -847,7 +849,7 @@ BOOST_AUTO_TEST_CASE(loadAdditionalConstraints_IncompleteRhsFile) ShortTermStorage::STStorageInput storageInput; ShortTermStorage::STStorageCluster cluster; - cluster.id = "ClusterA"; + cluster.id = "cluster1"; storageInput.storagesByIndex.push_back(cluster); bool result = storageInput.loadAdditionalConstraints(testPath);