mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-11-25 10:40:21 -06:00
Simplify the message for keywords with only a single record
This commit is contained in:
parent
fcba55080f
commit
ad0b62ab1c
@ -39,15 +39,20 @@ namespace KeywordValidation
|
||||
std::string get_error_report(const std::vector<ValidationError>& errors, const bool critical)
|
||||
{
|
||||
const std::string keyword_format = " {keyword}: keyword not supported\n";
|
||||
const std::string item_format = " {{keyword}}: invalid value '{}' in record {} for item {}\n";
|
||||
const std::string item_format1 = " {{keyword}}: invalid value '{}' for item {}\n";
|
||||
const std::string item_format2 = " {{keyword}}: invalid value '{}' in record {} for item {}\n";
|
||||
const std::string location_format = " In file: {file}, line {line}\n";
|
||||
|
||||
std::string report;
|
||||
for (const ValidationError& err : errors) {
|
||||
if (err.critical == critical) {
|
||||
if (err.item_number && err.item_value) {
|
||||
std::string message
|
||||
= fmt::format(item_format, *(err.item_value), err.record_number, *(err.item_number));
|
||||
std::string message;
|
||||
if (err.record_number == 0) {
|
||||
message = fmt::format(item_format1, *(err.item_value), *(err.item_number));
|
||||
} else {
|
||||
message = fmt::format(item_format2, *(err.item_value), err.record_number, *(err.item_number));
|
||||
}
|
||||
report.append(OpmInputError::format(message, err.location));
|
||||
} else {
|
||||
report.append(OpmInputError::format(keyword_format, err.location));
|
||||
@ -124,8 +129,13 @@ namespace KeywordValidation
|
||||
const auto& item_properties = keyword_properties->second.find(item_index + 1);
|
||||
if (item_properties != keyword_properties->second.end()) {
|
||||
// Validate the item, if it is partially supported.
|
||||
validateKeywordItem<T>(
|
||||
keyword, item_properties->second, record_index, item_index, item.get<T>(0), errors);
|
||||
validateKeywordItem<T>(keyword,
|
||||
item_properties->second,
|
||||
keyword.size() > 1,
|
||||
record_index,
|
||||
item_index,
|
||||
item.get<T>(0),
|
||||
errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,6 +146,7 @@ namespace KeywordValidation
|
||||
template <typename T>
|
||||
void KeywordValidator::validateKeywordItem(const DeckKeyword& keyword,
|
||||
const PartiallySupportedKeywordProperties<T>& properties,
|
||||
const bool multiple_records,
|
||||
const size_t record_index,
|
||||
const size_t item_index,
|
||||
const T& item_value,
|
||||
@ -149,11 +160,13 @@ namespace KeywordValidation
|
||||
formatted_value = std::to_string(item_value);
|
||||
else
|
||||
formatted_value = item_value;
|
||||
// Add the relevant information to the vector of errors.
|
||||
// Add the relevant information to the vector of errors. Record and
|
||||
// index numbers start at 1, so add 1. Pass zero for the record
|
||||
// index if there is only a single record.
|
||||
errors.push_back(ValidationError {properties.critical,
|
||||
keyword.location(),
|
||||
record_index + 1, // record numbers start at 1
|
||||
item_index + 1, // item numbers start at 1
|
||||
multiple_records ? record_index + 1 : 0,
|
||||
item_index + 1,
|
||||
formatted_value,
|
||||
properties.message});
|
||||
}
|
||||
|
@ -106,6 +106,7 @@ namespace KeywordValidation
|
||||
template <typename T>
|
||||
void validateKeywordItem(const DeckKeyword& keyword,
|
||||
const PartiallySupportedKeywordProperties<T>& properties,
|
||||
const bool multiple_records,
|
||||
const size_t record_number,
|
||||
const size_t item_number,
|
||||
const T& item_value,
|
||||
|
@ -279,7 +279,7 @@ PINCH
|
||||
const auto report = get_error_report(errors, false);
|
||||
BOOST_CHECK(report
|
||||
== "Unsupported keywords or keyword items:\n\n"
|
||||
" PINCH: invalid value 'FOO' in record 1 for item 2\n"
|
||||
" PINCH: invalid value 'FOO' for item 2\n"
|
||||
" In file: <memory string>, line 2");
|
||||
}
|
||||
|
||||
@ -339,7 +339,7 @@ ENDSCALE
|
||||
const auto report = get_error_report(errors, false);
|
||||
BOOST_CHECK(report
|
||||
== "Unsupported keywords or keyword items:\n\n"
|
||||
" ENDSCALE: invalid value '0' in record 1 for item 3\n"
|
||||
" ENDSCALE: invalid value '0' for item 3\n"
|
||||
" In file: <memory string>, line 2");
|
||||
}
|
||||
|
||||
@ -374,7 +374,7 @@ ENDSCALE
|
||||
const auto report = get_error_report(errors, true);
|
||||
BOOST_CHECK(report
|
||||
== "Unsupported keywords or keyword items:\n\n"
|
||||
" ENDSCALE: invalid value '0' in record 1 for item 4\n"
|
||||
" ENDSCALE: invalid value '0' for item 4\n"
|
||||
" In file: <memory string>, line 2");
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ ENDSCALE
|
||||
" ECHO: keyword not supported\n"
|
||||
" In file: <memory string>, line 2\n"
|
||||
" This is not a critical error\n\n"
|
||||
" ENDSCALE: invalid value '0' in record 1 for item 3\n"
|
||||
" ENDSCALE: invalid value '0' for item 3\n"
|
||||
" In file: <memory string>, line 6");
|
||||
}
|
||||
|
||||
@ -452,7 +452,7 @@ ENDSCALE
|
||||
== "Unsupported keywords or keyword items:\n\n"
|
||||
" NOECHO: keyword not supported\n"
|
||||
" In file: <memory string>, line 3\n\n"
|
||||
" PINCH: invalid value 'FOO' in record 1 for item 4\n"
|
||||
" PINCH: invalid value 'FOO' for item 4\n"
|
||||
" In file: <memory string>, line 4\n"
|
||||
" This is a critical error");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user