diff --git a/src/cpp/lpnamer/input_reader/CandidatesINIReader.cpp b/src/cpp/lpnamer/input_reader/CandidatesINIReader.cpp index d3d1a034b..07aca2dd4 100644 --- a/src/cpp/lpnamer/input_reader/CandidatesINIReader.cpp +++ b/src/cpp/lpnamer/input_reader/CandidatesINIReader.cpp @@ -131,20 +131,26 @@ std::vector CandidatesINIReader::readCandidateData( std::vector result; INIReader reader(candidateFile.string()); - std::stringstream ss; + std::ostringstream err_msg; + const auto starting_pos = err_msg.tellp(); std::set sections = reader.Sections(); for (auto const §ionName : sections) { CandidateData candidateData = - readCandidateSection(candidateFile, reader, sectionName); + readCandidateSection(candidateFile, reader, sectionName, err_msg); result.push_back(candidateData); } - + err_msg.flush(); + err_msg.seekp(0, std::ios_base::end); + if (err_msg.tellp() != starting_pos) { + (*logger_)(LogUtils::LOGLEVEL::FATAL) << err_msg.str(); + std::exit(1); + } return result; } CandidateData CandidatesINIReader::readCandidateSection( const std::filesystem::path &candidateFile, const INIReader &reader, - const std::string §ionName) const { + const std::string §ionName, std::ostringstream &err_msg) const { CandidateData candidateData; candidateData.name = StringManip::StringUtils::ToLowercase( getStrVal(reader, sectionName, "name")); @@ -156,28 +162,27 @@ CandidateData CandidatesINIReader::readCandidateSection( candidateData.linkex = candidateData.link_name.substr(i + 3, candidateData.link_name.size()); if (!checkArea(candidateData.linkor)) { - (*logger_)(LogUtils::LOGLEVEL::FATAL) - << LOGLOCATION << "Unrecognized area " << candidateData.linkor - << " in section " << sectionName << " in " - << candidateFile.string() + "."; - std::exit(1); + err_msg << LOGLOCATION << "Unrecognized area " << candidateData.linkor + << " in section " << sectionName << " in " + << candidateFile.string() << "\n"; } if (!checkArea(candidateData.linkex)) { - (*logger_)(LogUtils::LOGLEVEL::FATAL) - << LOGLOCATION << "Unrecognized area " << candidateData.linkex - << " in section " << sectionName << " in " << candidateFile.string() - << "."; - std::exit(1); + err_msg << LOGLOCATION << "Unrecognized area " << candidateData.linkex + << " in section " << sectionName << " in " + << candidateFile.string() << "\n"; } } // Check if interco is available auto it = _intercoIndexMap.find(candidateData.link_name); if (it == _intercoIndexMap.end()) { - (*logger_)(LogUtils::LOGLEVEL::FATAL) - << LOGLOCATION << "cannot link candidate " << candidateData.name - << " to interco id"; - std::exit(1); + err_msg << LOGLOCATION << "cannot link candidate " << candidateData.name + << " to interco id" + << "\n"; + } + + if (err_msg.tellp() != 0) { + return {}; } candidateData.link_id = it->second; candidateData.direct_link_profile = diff --git a/src/cpp/lpnamer/input_reader/CandidatesINIReader.h b/src/cpp/lpnamer/input_reader/CandidatesINIReader.h index 8967a8d2d..7ca622d33 100644 --- a/src/cpp/lpnamer/input_reader/CandidatesINIReader.h +++ b/src/cpp/lpnamer/input_reader/CandidatesINIReader.h @@ -45,7 +45,8 @@ class CandidatesINIReader { bool checkArea(std::string const& areaName_p) const; CandidateData readCandidateSection(const std::filesystem::path& candidateFile, const INIReader& reader, - const std::string& sectionName) const; + const std::string& sectionName, + std::ostringstream& err_msg) const; std::map _intercoIndexMap; std::vector _intercoFileData; diff --git a/src/python/antares_xpansion/config_loader.py b/src/python/antares_xpansion/config_loader.py index 7330b4736..d4b560a3e 100644 --- a/src/python/antares_xpansion/config_loader.py +++ b/src/python/antares_xpansion/config_loader.py @@ -501,7 +501,7 @@ def _set_last_simulation_name(self): """ return last simulation name """ - self._last_study = self.last_modified_study(self.antares_output()) + self._last_study = self.last_modified_study(Path(self.antares_output())) self._set_xpansion_simulation_name() class NotAnXpansionOutputDir(Exception): @@ -535,14 +535,14 @@ def update_last_study_with_sensitivity_results(self): if(os.path.exists(self._xpansion_simulation_name)): shutil.rmtree(self._xpansion_simulation_name) - def is_antares_study_output(self, study): + def is_antares_study_output(self, study: Path): _, ext = os.path.splitext(study) - return ext == ".zip" or os.path.isdir(study) + return ext == ".zip" or os.path.isdir(study) and '-Xpansion' not in study.name - def last_modified_study(self, root_dir)-> Path: + def last_modified_study(self, root_dir:Path)-> Path: list_dir = os.listdir(root_dir) list_of_studies = filter( - lambda x: self.is_antares_study_output(os.path.join(root_dir, x)), list_dir + lambda x: self.is_antares_study_output(root_dir / x), list_dir ) # Sort list of files based on last modification time in ascending order sort_studies = sorted( diff --git a/src/python/antares_xpansion/input_checker.py b/src/python/antares_xpansion/input_checker.py index 2c5679721..cc248a7e2 100644 --- a/src/python/antares_xpansion/input_checker.py +++ b/src/python/antares_xpansion/input_checker.py @@ -216,12 +216,15 @@ class MaxUnitsAndMaxInvestmentAreNullSimultaneously(Exception): def _check_candidate_attributes(ini_file): # check attributes types and values + err_msg = "" for each_section in ini_file.sections(): for (option, value) in ini_file.items(each_section): if not _check_candidate_option_type(option, value): - logger.error( - f"value {value} for option {option} has the wrong type!, it has to be {candidate_options_type[option]}") - raise CandidateFileWrongTypeValue + err_msg += f"value {value} for option {option} has the wrong type, it has to be {candidate_options_type[option]}\n" + + if(err_msg!=""): + logger.error(err_msg) + raise CandidateFileWrongTypeValue def _check_name_is_unique(ini_file):