Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove getErrorMessage, use dedicated struct #2542

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ struct AdditionalConstraint

unsigned int globalIndex = 0;

bool validate() const;
struct ValidateResult
{
bool ok;
std::string error_msg;
};

bool isValidVariable() const;
ValidateResult validate() const;

private:
bool isValidVariable() const;
bool isValidOperatorType() const;

bool isValidHoursRange() const;

mutable std::string error_message = "";

std::string getErrorMessage() const
{
return error_message;
}
};
} // namespace Antares::Data::ShortTermStorage
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,29 @@

namespace Antares::Data::ShortTermStorage
{
bool AdditionalConstraint::validate() const
AdditionalConstraint::ValidateResult AdditionalConstraint::validate() const
{
if (cluster_id.empty())
{
error_message = "Cluster ID is empty.";
return false;
return {false, "Cluster ID is empty."};
}

if (!isValidVariable())
{
error_message = "Invalid variable type. Must be 'injection', 'withdrawal', or 'netting'.";
return false;
return {false, "Invalid variable type. Must be 'injection', 'withdrawal', or 'netting'."};
}

if (!isValidOperatorType())
{
error_message = "Invalid operator type. Must be 'less', 'equal', or 'greater'.";
return false;
return {false, "Invalid operator type. Must be 'less', 'equal', or 'greater'."};
}

if (!isValidHoursRange())
{
error_message = "Hours set contains invalid values. Must be between 1 and 168.";
return false;
return {false, "Hours set contains invalid values. Must be between 1 and 168."};
}

error_message.clear();
return true;
return {true, ""};
}

bool AdditionalConstraint::isValidHoursRange() const
Expand Down
8 changes: 5 additions & 3 deletions src/libs/antares/study/parts/short-term-storage/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)
}
}

if (!constraint.validate())
if (auto ret = constraint.validate(); !ret.ok)
{
throw std::runtime_error("Invalid constraint in section: " + section->name + "\n"
+ constraint.getErrorMessage());
logs.error() << "Invalid constraint in section: " << section->name;
logs.error() << ret.error_msg;
return false;
}

auto it = std::find_if(storagesByIndex.begin(),
Expand All @@ -140,6 +141,7 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)
logs.warning() << " from file " << pathIni;
logs.warning() << "Constraint " << section->name
<< " does not reference an existing cluster";
return false;
}
else
{
Expand Down
Loading