Refactor get_error_report() for more flexibility.

This commit is contained in:
Atgeirr Flø Rasmussen
2023-04-25 10:33:20 +02:00
parent 4bf2dd7269
commit 77d151e0b5
3 changed files with 24 additions and 22 deletions

View File

@@ -31,6 +31,7 @@
#include <opm/input/eclipse/Deck/Deck.hpp>
#include <opm/input/eclipse/Deck/DeckKeyword.hpp>
#include <opm/input/eclipse/Parser/ErrorGuard.hpp>
#include <opm/input/eclipse/Parser/InputErrorAction.hpp>
#include <opm/input/eclipse/Parser/ParseContext.hpp>
#include <opm/simulators/flow/KeywordValidation.hpp>
@@ -43,7 +44,7 @@ namespace KeywordValidation
{
std::string get_error_report(const std::vector<ValidationError>& errors, const bool critical)
std::string get_error_report(const std::vector<ValidationError>& errors, const bool include_noncritical, const bool include_critical)
{
const std::string keyword_format = " {keyword}: keyword not supported\n";
const std::string item_format1 = " {{keyword}}: invalid value '{}' for item {}\n";
@@ -52,7 +53,7 @@ namespace KeywordValidation
std::string report;
for (const ValidationError& err : errors) {
if (err.critical == critical) {
if ((err.critical && include_critical) || (!err.critical && include_noncritical)) {
if (err.item_number && err.item_value) {
std::string message;
if (err.record_number == 0) {
@@ -99,14 +100,14 @@ namespace KeywordValidation
}
// First report non-critical problems as a warning.
auto warning_report = get_error_report(errors, false);
auto warning_report = get_error_report(errors, true, false);
if (!warning_report.empty()) {
parse_context.handleError(
ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED, warning_report, std::nullopt, error_guard);
}
// Then report critical problems as an error.
auto error_report = get_error_report(errors, true);
auto error_report = get_error_report(errors, false, true);
if (!error_report.empty()) {
parse_context.handleError(
ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED_CRITICAL, error_report, std::nullopt, error_guard);

View File

@@ -78,11 +78,12 @@ namespace KeywordValidation
};
// Get a formatted error report from a vector of validation errors. Set
// critical to true if the report should contain only critical errors. If
// critical is false, only non-critical errors are reported. If not
// critical/non-critical errors are present, but the critical flag to reset
// them, the result will be an empty string.
std::string get_error_report(const std::vector<ValidationError>& errors, const bool critical);
// include_noncritical to true if the report should include noncritical errors, and
// include_critical to true if the report should include critical errors. These may
// be set independently. If no errors are included the result will be an empty string.
std::string get_error_report(const std::vector<ValidationError>& errors,
const bool include_noncritical,
const bool include_critical);