From 8c2ed38cf461aea4aeb4093756a099d78cc53cbd Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 25 Sep 2020 09:40:36 +0200 Subject: [PATCH] Parse differentiates between OpmInputError and std::exception --- src/opm/output/eclipse/Summary.cpp | 1 + .../EclipseState/Schedule/VFPProdTable.cpp | 2 ++ src/opm/parser/eclipse/Parser/Parser.cpp | 17 ++++++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/opm/output/eclipse/Summary.cpp b/src/opm/output/eclipse/Summary.cpp index 18dee0bee..0bb95757a 100644 --- a/src/opm/output/eclipse/Summary.cpp +++ b/src/opm/output/eclipse/Summary.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp index 26b47c5a8..7bb22cfdc 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp @@ -22,6 +22,8 @@ #include #include +#include + #include #include diff --git a/src/opm/parser/eclipse/Parser/Parser.cpp b/src/opm/parser/eclipse/Parser/Parser.cpp index fb1b08063..59eef4aa4 100644 --- a/src/opm/parser/eclipse/Parser/Parser.cpp +++ b/src/opm/parser/eclipse/Parser/Parser.cpp @@ -31,6 +31,7 @@ #include #include +#include #include @@ -920,15 +921,25 @@ bool parseState( ParserState& parserState, const Parser& parser ) { *rawKeyword, parserState.deck.getActiveUnitSystem(), parserState.deck.getDefaultUnitSystem())); - } catch (const std::exception& exc) { + } catch (const OpmInputError& opm_error) { + throw; + } + catch (const std::exception& std_error) { /* This catch-all of parsing errors is to be able to write a good error message; the parser is quite confused at this state and we should not be tempted to continue the parsing. + + We log a error message with the name of the problematic + keyword and the location in the input deck. We rethrow the + same exception without updating the what() message of the + exception. */ const auto& location = rawKeyword->location(); - std::string msg = Log::fileMessage(location, "Parse error: " + std::string{ exc.what() }); - OpmLog::error(msg); + std::string msg_fmt = fmt::format("Problem parsing keyword {{keyword}}\n" + "In {{file}} line {{line}}.\n" + "Internal error message: {}" , std_error.what()); + OpmLog::error( OpmInputError::format(msg_fmt, location) ); throw; } } else {