Make KeywordValidation::validateDeck() more flexible.

Adding a bool argument 'treat_critical_as_noncritical' to possibly
reduce terminating errors to warnings.
This commit is contained in:
Atgeirr Flø Rasmussen 2023-04-25 10:44:59 +02:00
parent 77d151e0b5
commit 04d2b8f39d
3 changed files with 26 additions and 13 deletions

View File

@ -85,6 +85,7 @@ namespace KeywordValidation
void
KeywordValidator::validateDeck(const Deck& deck,
const ParseContext& parse_context,
const bool treat_critical_as_noncritical,
ErrorGuard& error_guard) const
{
// Make a vector with all problems encountered in the deck.
@ -99,18 +100,27 @@ namespace KeywordValidation
}
}
// First report non-critical problems as a warning.
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);
}
if (treat_critical_as_noncritical) {
// Get both critical and noncritical errors.
auto warning_report = get_error_report(errors, true, true);
if (!warning_report.empty()) {
// Report all as warnings.
parse_context.handleError(ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED, warning_report, std::nullopt, error_guard);
}
} else {
// First report non-critical problems as a warning.
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, false, true);
if (!error_report.empty()) {
parse_context.handleError(
ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED_CRITICAL, error_report, std::nullopt, error_guard);
// Then report critical problems as an error.
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

@ -110,9 +110,12 @@ namespace KeywordValidation
// Validate a deck, reporting warnings and errors. If there are only
// warnings, these will be reported. If there are errors, these are
// reported, and execution of the program is halted.
// reported, and execution of the program is halted, unless the argument
// treat_critical_as_noncritical is true, then these also will only be
// reported and not cause termination.
void validateDeck(const Deck& deck,
const ParseContext& parse_context,
const bool treat_critical_as_noncritical,
ErrorGuard& error_guard) const;
// Validate a single deck keyword. If a problem is encountered, add the

View File

@ -203,7 +203,7 @@ namespace {
Opm::KeywordValidation::specialValidation()
};
keyword_validator.validateDeck(deck, parseContext, errorGuard);
keyword_validator.validateDeck(deck, parseContext, true, errorGuard);
if (checkDeck) {
Opm::checkDeck(deck, parser, parseContext, errorGuard);