diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index af1d4177cc..946acd8561 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -32,11 +32,22 @@ class HydroErrorsCollector void Collect(const std::string& area_name, const std::string& message); void Collect(const std::string& message); void CheckForFatalErrors() const; + template + std::ostream& operator<<(const T& obj); private: + // for log + constexpr unsigned int TRHESHOLD_NUMBER_OF_ERRORS_FOR_ONE_AREA = 10; std::map area_errors_counter_; bool errors_limit_reached_ = false; bool stop_ = false; // std::vector fatal_errors_; }; + +template +HydroErrorsCollector& HydroErrorsCollector::operator<<(const T& obj) +{ + logs.error() << obj; + return *this; +} } // namespace Antares diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index ec8152e836..93374314d4 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -9,13 +9,14 @@ namespace Antares void HydroErrorsCollector::Collect(const std::string& area_name, const std::string& message) { logs.error() << "In Area " << area_name << " " << message; - area_errors_counter_[area_name]++; - errors_limit_reached_ = area_errors_counter_[area_name] > 10; + auto error_count = area_errors_counter_[area_name]++; + errors_limit_reached_ = error_count > TRHESHOLD_NUMBER_OF_ERRORS_FOR_ONE_AREA; stop_ = true; if (errors_limit_reached_) { - throw FatalError("Hydro validation has failed !"); + logs.error() << "Hydro validation has failed !"; + logs.error() << error_count << " errors found in Area " << area_name; } } @@ -27,7 +28,7 @@ void HydroErrorsCollector::Collect(const std::string& message) void HydroErrorsCollector::CheckForFatalErrors() const { - if (stop_ || errors_limit_reached_) + if (stop_) { throw FatalError("Hydro validation has failed !"); }