Adjusts the defaultMessage format string.
This commit is contained in:
parent
7a8347f1ab
commit
d0c5fa042c
@ -103,7 +103,6 @@ public:
|
||||
|
||||
|
||||
static std::string format(const std::string& msg_format, const KeywordLocation& loc);
|
||||
static std::string formatException(const std::exception& e, const KeywordLocation& loc);
|
||||
|
||||
private:
|
||||
// The location member is here for debugging; depending on the msg_fmt
|
||||
@ -113,6 +112,7 @@ private:
|
||||
|
||||
std::string m_what;
|
||||
|
||||
static std::string formatException(const std::exception& e, const KeywordLocation& loc);
|
||||
static std::string formatSingle(const std::string& reason, const KeywordLocation&);
|
||||
static std::string formatMultiple(const std::string& reason, const std::vector<KeywordLocation>&);
|
||||
};
|
||||
|
@ -41,7 +41,7 @@ std::string formatImpl(const std::string& msg_format, const KeywordLocation& loc
|
||||
}
|
||||
|
||||
std::string OpmInputError::formatException(const std::exception& e, const KeywordLocation& loc) {
|
||||
const std::string defaultMessage { R"(Problem parsing keyword {keyword}
|
||||
const std::string defaultMessage { R"(Problem with keyword {keyword}
|
||||
In {file} line {line}.
|
||||
Internal error: {})" } ;
|
||||
|
||||
@ -60,9 +60,9 @@ std::string OpmInputError::format(const std::string& msg_format, const KeywordLo
|
||||
}
|
||||
|
||||
std::string OpmInputError::formatSingle(const std::string& reason, const KeywordLocation& location) {
|
||||
const std::string defaultMessage { R"(Problem parsing keyword {keyword}
|
||||
const std::string defaultMessage { R"(Problem with keyword {keyword}
|
||||
In {file} line {line}
|
||||
Parse error: {})" } ;
|
||||
{})" } ;
|
||||
|
||||
return formatImpl(defaultMessage, location, reason);
|
||||
}
|
||||
@ -80,8 +80,8 @@ std::string OpmInputError::formatMultiple(const std::string& reason, const std::
|
||||
std::transform(locations.begin(), locations.end(), std::back_inserter(locationStrings), &locationStringLine);
|
||||
const std::string messages { std::accumulate(locationStrings.begin(), locationStrings.end(), std::string {}) } ;
|
||||
|
||||
return fmt::format(R"(Problem parsing keywords {}
|
||||
Parse error: {})", messages, reason);
|
||||
return fmt::format(R"(Problem with keywords {}
|
||||
{})", messages, reason);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1767,8 +1767,13 @@ namespace {
|
||||
} catch (const OpmInputError&) {
|
||||
throw;
|
||||
} catch (const std::exception& e) {
|
||||
OpmLog::error(OpmInputError::formatException(e, handlerContext.keyword.location()));
|
||||
const OpmInputError opm_error { e, handlerContext.keyword.location() } ;
|
||||
|
||||
OpmLog::error(opm_error.what());
|
||||
|
||||
// Ideally, we'd be doing this, but the ramifications are not clear p.t.
|
||||
// std::throw_with_nested(opm_error);
|
||||
// So we're doing this instead
|
||||
throw;
|
||||
}
|
||||
|
||||
|
@ -162,10 +162,8 @@ namespace Opm {
|
||||
// make sure the error object does not terminate the application
|
||||
// when it goes out of scope.
|
||||
errors.clear();
|
||||
if (location)
|
||||
throw OpmInputError(msg_fmt, *location);
|
||||
else
|
||||
throw OpmInputError(msg_fmt, {});
|
||||
|
||||
throw OpmInputError(msg_fmt, location.value_or(KeywordLocation{}));
|
||||
}
|
||||
|
||||
if (action == InputError::EXIT1) {
|
||||
|
@ -934,10 +934,11 @@ bool parseState( ParserState& parserState, const Parser& parser ) {
|
||||
same exception without updating the what() message of the
|
||||
exception.
|
||||
*/
|
||||
const OpmInputError opm_error { e, rawKeyword->location() } ;
|
||||
|
||||
OpmLog::error(OpmInputError::formatException(e, rawKeyword->location()));
|
||||
OpmLog::error(opm_error.what());
|
||||
|
||||
throw;
|
||||
std::throw_with_nested(opm_error);
|
||||
}
|
||||
} else {
|
||||
const std::string msg = "The keyword " + rawKeyword->getKeywordName() + " is not recognized - ignored";
|
||||
|
@ -2125,7 +2125,7 @@ FIELD
|
||||
section in order to provoke the exception; if at some stage the opm parser
|
||||
treats section stricter this test might fail due to that reason instead.
|
||||
*/
|
||||
BOOST_CHECK_THROW( Parser{}.parseString(deck_string), std::invalid_argument);
|
||||
BOOST_CHECK_THROW( Parser{}.parseString(deck_string), OpmInputError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseRSConstT) {
|
||||
|
@ -49,28 +49,8 @@ BOOST_AUTO_TEST_CASE(positional) {
|
||||
BOOST_CHECK_EQUAL(formatted, expected);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(exception) {
|
||||
const std::string expected { R"(Problem parsing keyword MXUNSUPP
|
||||
In FILENAME.DAT line 42.
|
||||
Internal error: Runtime Error)" };
|
||||
|
||||
const std::string formatted { Opm::OpmInputError::formatException(std::runtime_error("Runtime Error"), location) } ;
|
||||
|
||||
BOOST_CHECK_EQUAL(formatted, expected);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(exception_reason) {
|
||||
const std::string expected { R"(Problem parsing keyword MXUNSUPP
|
||||
In FILENAME.DAT line 42.
|
||||
Internal error: Runtime Error)" };
|
||||
|
||||
const std::string formatted { Opm::OpmInputError::formatException(std::runtime_error("Runtime Error"), location) } ;
|
||||
|
||||
BOOST_CHECK_EQUAL(formatted, expected);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(exception_init) {
|
||||
const std::string expected { R"(Problem parsing keyword MXUNSUPP
|
||||
const std::string expected { R"(Problem with keyword MXUNSUPP
|
||||
In FILENAME.DAT line 42.
|
||||
Internal error: Runtime Error)" };
|
||||
|
||||
@ -80,7 +60,7 @@ Internal error: Runtime Error)" };
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(exception_nest) {
|
||||
const std::string expected { R"(Problem parsing keyword MXUNSUPP
|
||||
const std::string expected { R"(Problem with keyword MXUNSUPP
|
||||
In FILENAME.DAT line 42.
|
||||
Internal error: Runtime Error)" };
|
||||
|
||||
@ -98,9 +78,9 @@ Internal error: Runtime Error)" };
|
||||
const Opm::KeywordLocation location2 { "MZUNSUPP", "FILENAME.DAT", 45 } ;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(exception_multi_1) {
|
||||
const std::string expected { R"(Problem parsing keyword MXUNSUPP
|
||||
const std::string expected { R"(Problem with keyword MXUNSUPP
|
||||
In FILENAME.DAT line 42
|
||||
Parse error: Runtime Error)" } ;
|
||||
Runtime Error)" } ;
|
||||
|
||||
const std::string formatted { Opm::OpmInputError("Runtime Error", location).what() } ;
|
||||
|
||||
@ -108,10 +88,10 @@ Parse error: Runtime Error)" } ;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(exception_multi_2) {
|
||||
const std::string expected { R"(Problem parsing keywords
|
||||
const std::string expected { R"(Problem with keywords
|
||||
MXUNSUPP in FILENAME.DAT, line 42
|
||||
MZUNSUPP in FILENAME.DAT, line 45
|
||||
Parse error: Runtime Error)" } ;
|
||||
Runtime Error)" } ;
|
||||
|
||||
const std::string formatted { Opm::OpmInputError("Runtime Error", location, location2).what() } ;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user