From 0512ab88b420f2c7b521589c5e1678546701abc7 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 25 Sep 2020 08:46:27 +0200 Subject: [PATCH] ParseContext will throw OpmInputError --- opm/common/utility/OpmInputError.hpp | 7 +++- src/opm/output/eclipse/Summary.cpp | 3 +- .../EclipseState/Schedule/VFPProdTable.cpp | 14 +++---- .../SummaryConfig/SummaryConfig.cpp | 2 +- .../parser/eclipse/Parser/ParseContext.cpp | 11 +++-- tests/parser/ACTIONX.cpp | 5 ++- tests/parser/MultisegmentWellTests.cpp | 5 ++- tests/parser/ParseContextTests.cpp | 42 +++++++++++-------- tests/parser/ParserIncludeTests.cpp | 9 ++-- tests/parser/ParserTests.cpp | 9 ++-- tests/parser/RestartConfigTests.cpp | 6 +-- tests/parser/ScheduleTests.cpp | 9 ++-- tests/parser/SummaryConfigTests.cpp | 13 +++--- tests/parser/UDQTests.cpp | 9 ++-- .../someobscureelements.data | 15 ------- tests/parser/integration/IntegrationTests.cpp | 33 ++++++++++++++- tests/parser/integration/ParseKEYWORD.cpp | 5 ++- tests/test_ArrayDimChecker.cpp | 5 ++- 18 files changed, 120 insertions(+), 82 deletions(-) delete mode 100644 tests/parser/data/integration_tests/someobscureelements.data diff --git a/opm/common/utility/OpmInputError.hpp b/opm/common/utility/OpmInputError.hpp index 3b27be4fa..f4a2fae95 100644 --- a/opm/common/utility/OpmInputError.hpp +++ b/opm/common/utility/OpmInputError.hpp @@ -19,6 +19,7 @@ #ifndef OPM_ERROR_HPP #define OPM_ERROR_HPP +#include #include #include #include @@ -94,6 +95,10 @@ public: location { loc } {} + OpmInputError(const std::string& msg) : + m_what(msg) + {} + const char * what() const throw() { return this->m_what.c_str(); @@ -124,7 +129,7 @@ private: // The location member is here for debugging; depending on the msg_fmt // passed in the constructor we might not have captured all the information // in the location argument passed to the constructor. - KeywordLocation location; + std::optional location; }; } diff --git a/src/opm/output/eclipse/Summary.cpp b/src/opm/output/eclipse/Summary.cpp index ceb536d15..05858b18c 100644 --- a/src/opm/output/eclipse/Summary.cpp +++ b/src/opm/output/eclipse/Summary.cpp @@ -2204,7 +2204,8 @@ void reportUnsupportedKeywords(std::vector keywords) for (auto node = keywords.begin(); node != uend; ++node) { const auto& location = node->location(); - ::Opm::OpmLog::warning("Unhandled summary keyword '" + node->keyword() + "' at " + location.filename + ", line " + std::to_string(location.lineno)); + Opm::OpmLog::warning(Opm::OpmInputError::format("Unhandled summary keyword {keyword}\n" + "In {file} line {line}", location)); } } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp index 7bb22cfdc..f883b1187 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.cpp @@ -411,14 +411,12 @@ void VFPProdTable::check(const DeckKeyword& keyword, const double table_scaling_ if (!points.empty()) { const auto& location = keyword.location(); - OpmLog::warning("VFP table for production wells has BHP versus THP not " - + std::string("monotonically increasing.\nThis may cause convergence ") - + "issues due to switching between BHP and THP control mode." - + std::string("\nIn keyword VFPPROD table number ") - + std::to_string(m_table_num) - + ", file " + location.filename - + ", line " + std::to_string(location.lineno) - + "\n"); + OpmLog::warning(fmt::format("VFP table {0} has BHP versus THP not increasing in keyword VFPPROD.\n" + "In {1} line {2}\n" + "This may cause convergence issues due to switching between BHP and THP control.", + m_table_num, + location.filename, + location.lineno)); OpmLog::note(points); } } diff --git a/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp b/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp index e45b224c3..0fb65113d 100644 --- a/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp +++ b/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp @@ -562,7 +562,7 @@ inline void keywordR2R( SummaryConfig::keyword_list& /* list */, const DeckKeyword& keyword) { const auto& location = keyword.location(); - std::string msg_fmt = "Region to region summary keyword {keyword} is ignored\n"; + std::string msg_fmt = "Region to region summary keyword {keyword} is ignored\n" "In {file} line {line}"; parseContext.handleError(ParseContext::SUMMARY_UNHANDLED_KEYWORD, msg_fmt, location, errors); } diff --git a/src/opm/parser/eclipse/Parser/ParseContext.cpp b/src/opm/parser/eclipse/Parser/ParseContext.cpp index 3dde706d2..1d47467e4 100644 --- a/src/opm/parser/eclipse/Parser/ParseContext.cpp +++ b/src/opm/parser/eclipse/Parser/ParseContext.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace Opm { @@ -137,11 +138,12 @@ namespace Opm { void ParseContext::handleError( const std::string& errorKey, - const std::string& msg, + const std::string& msg_fmt, const std::optional& location, ErrorGuard& errors) const { InputError::Action action = get( errorKey ); + std::string msg = location ? OpmInputError::format(msg_fmt, *location) : msg_fmt; if (action == InputError::IGNORE) { errors.addWarning(errorKey, msg); @@ -160,7 +162,10 @@ namespace Opm { // make sure the error object does not terminate the application // when it goes out of scope. errors.clear(); - throw std::invalid_argument(errorKey + ": " + msg); + if (location) + throw OpmInputError(msg_fmt, *location); + else + throw OpmInputError(msg_fmt, {}); } if (action == InputError::EXIT1) { @@ -177,7 +182,7 @@ namespace Opm { } } -void ParseContext::handleUnknownKeyword(const std::string& keyword, const std::optional& location, ErrorGuard& errors) const { + void ParseContext::handleUnknownKeyword(const std::string& keyword, const std::optional& location, ErrorGuard& errors) const { if (this->ignore_keywords.find(keyword) == this->ignore_keywords.end()) { std::string msg = "Unknown keyword: " + keyword; this->handleError(ParseContext::PARSE_UNKNOWN_KEYWORD, msg, location, errors); diff --git a/tests/parser/ACTIONX.cpp b/tests/parser/ACTIONX.cpp index b39bea749..e69e55ff5 100644 --- a/tests/parser/ACTIONX.cpp +++ b/tests/parser/ACTIONX.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -137,7 +138,7 @@ TSTEP Runspec runspec (deck1); // The ACTIONX keyword has no matching 'ENDACTIO' -> exception - BOOST_CHECK_THROW(Schedule(deck1, grid1, fp, runspec, python), std::invalid_argument); + BOOST_CHECK_THROW(Schedule(deck1, grid1, fp, runspec, python), OpmInputError); Schedule sched(deck2, grid1, fp, runspec, python); BOOST_CHECK( !sched.hasWell("W1") ); @@ -146,7 +147,7 @@ TSTEP // The deck3 contains the 'GRID' keyword in the ACTIONX block - that is not a whitelisted keyword. ParseContext parseContext( {{ParseContext::ACTIONX_ILLEGAL_KEYWORD, InputError::THROW_EXCEPTION}} ); ErrorGuard errors; - BOOST_CHECK_THROW(Schedule(deck3, grid1, fp, runspec, parseContext, errors, python), std::invalid_argument); + BOOST_CHECK_THROW(Schedule(deck3, grid1, fp, runspec, parseContext, errors, python), OpmInputError); } diff --git a/tests/parser/MultisegmentWellTests.cpp b/tests/parser/MultisegmentWellTests.cpp index 2987ba4bb..14ff627e4 100644 --- a/tests/parser/MultisegmentWellTests.cpp +++ b/tests/parser/MultisegmentWellTests.cpp @@ -30,6 +30,7 @@ #include +#include #include #include #include @@ -395,7 +396,7 @@ BOOST_AUTO_TEST_CASE(WrongDistanceCOMPSEGS) { Opm::ErrorGuard errorGuard; Opm::ParseContext parseContext; parseContext.update(Opm::ParseContext::SCHEDULE_COMPSEGS_INVALID, Opm::InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW(Opm::Compsegs::processCOMPSEGS(compsegs, connection_set, segment_set, grid, parseContext, errorGuard), std::invalid_argument); + BOOST_CHECK_THROW(Opm::Compsegs::processCOMPSEGS(compsegs, connection_set, segment_set, grid, parseContext, errorGuard), Opm::OpmInputError); parseContext.update(Opm::ParseContext::SCHEDULE_COMPSEGS_INVALID, Opm::InputError::IGNORE); BOOST_CHECK_NO_THROW(Opm::Compsegs::processCOMPSEGS(compsegs, connection_set, segment_set, grid, parseContext, errorGuard)); @@ -452,7 +453,7 @@ BOOST_AUTO_TEST_CASE(NegativeDepthCOMPSEGS) { Opm::ErrorGuard errorGuard; Opm::ParseContext parseContext; parseContext.update(Opm::ParseContext::SCHEDULE_COMPSEGS_NOT_SUPPORTED, Opm::InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW(Opm::Compsegs::processCOMPSEGS(compsegs, connection_set, segment_set, grid, parseContext, errorGuard), std::invalid_argument); + BOOST_CHECK_THROW(Opm::Compsegs::processCOMPSEGS(compsegs, connection_set, segment_set, grid, parseContext, errorGuard), Opm::OpmInputError); parseContext.update(Opm::ParseContext::SCHEDULE_COMPSEGS_NOT_SUPPORTED, Opm::InputError::IGNORE); BOOST_CHECK_NO_THROW( Opm::Compsegs::processCOMPSEGS(compsegs, connection_set, segment_set, grid, parseContext, errorGuard) ); diff --git a/tests/parser/ParseContextTests.cpp b/tests/parser/ParseContextTests.cpp index b9867757b..228a3564a 100644 --- a/tests/parser/ParseContextTests.cpp +++ b/tests/parser/ParseContextTests.cpp @@ -73,14 +73,14 @@ BOOST_AUTO_TEST_CASE(TestUnkownKeyword) { parser.addKeyword(); parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deck1 , parseContext , errors) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deck1 , parseContext , errors) , OpmInputError); parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); BOOST_CHECK_NO_THROW( parser.parseString( deck1 , parseContext , errors) ); parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::THROW_EXCEPTION ); parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::IGNORE ); - BOOST_CHECK_THROW( parser.parseString( deck2 , parseContext , errors) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deck2 , parseContext , errors) , OpmInputError); parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::IGNORE ); @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(TestUnkownKeyword) { parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deck2 , parseContext , errors) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deck2 , parseContext , errors) , OpmInputError); parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::IGNORE ); @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(TestUnkownKeywordII) { parser.addKeyword(); parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deck1 , parseContext, errors ) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deck1 , parseContext, errors ) , OpmInputError); parseContext.ignoreKeyword("RUNSPEC"); BOOST_CHECK_NO_THROW( parser.parseString( deck1 , parseContext, errors ) ); } @@ -135,14 +135,14 @@ BOOST_AUTO_TEST_CASE(Handle_extra_records) { parser.addKeyword(); parser.addKeyword(); parser.addKeyword(); - BOOST_CHECK_THROW( parser.parseString( deck_string , parseContext, errors ) , std::invalid_argument ); + BOOST_CHECK_THROW( parser.parseString( deck_string , parseContext, errors ) , OpmInputError ); parseContext.update(ParseContext::PARSE_EXTRA_RECORDS , InputError::IGNORE ); parser.parseString( deck_string , parseContext, errors ); BOOST_CHECK( parser.hasKeyword( "GRID" ) ); parseContext.update(ParseContext::PARSE_EXTRA_RECORDS , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deck_string , parseContext, errors ) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deck_string , parseContext, errors ) , OpmInputError); } @@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(Handle_extra_records_2) { parser.addKeyword(); parseContext.update(ParseContext::PARSE_EXTRA_RECORDS , InputError::IGNORE ); - BOOST_CHECK_THROW( parser.parseString( deck_string , parseContext, errors ), std::invalid_argument ); + BOOST_CHECK_THROW( parser.parseString( deck_string , parseContext, errors ), OpmInputError ); } @@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(TestUnkownKeyword_DATA) { BOOST_CHECK( deck.hasKeyword( "RUNSPEC") ); BOOST_CHECK( deck.hasKeyword( "DIMENS") ); } - BOOST_CHECK_THROW( parser.parseString( deck_string2 , parseContext, errors ) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deck_string2 , parseContext, errors ) , OpmInputError); } @@ -247,7 +247,7 @@ BOOST_AUTO_TEST_CASE(TEST_UNKNOWN_OPERATE) { Parser parser(false); parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deck , parseContext, errors ) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deck , parseContext, errors ) , OpmInputError); parseContext.update(ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE ); parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); @@ -280,7 +280,7 @@ BOOST_AUTO_TEST_CASE( CheckMissingSizeKeyword) { parser.addKeyword(); parseContext.update( ParseContext::PARSE_MISSING_DIMS_KEYWORD , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deck , parseContext, errors ) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deck , parseContext, errors ) , OpmInputError); parseContext.update( ParseContext::PARSE_MISSING_DIMS_KEYWORD , InputError::IGNORE ); BOOST_CHECK_NO_THROW( parser.parseString( deck , parseContext, errors ) ); @@ -346,7 +346,7 @@ BOOST_AUTO_TEST_CASE( CheckUnsupportedInSCHEDULE ) { BOOST_CHECK_NO_THROW( Schedule( deckUnSupported, grid , fp, runspec, parseContext, errors, python )); parseContext.update( ParseContext::UNSUPPORTED_SCHEDULE_GEO_MODIFIER , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( Schedule( deckUnSupported , grid , fp, runspec , parseContext , errors, python), std::invalid_argument ); + BOOST_CHECK_THROW( Schedule( deckUnSupported , grid , fp, runspec , parseContext , errors, python), OpmInputError ); BOOST_CHECK_NO_THROW( Schedule( deckSupported , grid , fp, runspec , parseContext, errors, python)); } @@ -376,8 +376,8 @@ BOOST_AUTO_TEST_CASE(TestRandomSlash) { parseContext.update(ParseContext::PARSE_RANDOM_SLASH , InputError::THROW_EXCEPTION); parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::IGNORE); - BOOST_CHECK_THROW( parser.parseString( deck1 , parseContext, errors ) , std::invalid_argument); - BOOST_CHECK_THROW( parser.parseString( deck2 , parseContext, errors ) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deck1 , parseContext, errors ) , OpmInputError); + BOOST_CHECK_THROW( parser.parseString( deck2 , parseContext, errors ) , OpmInputError); parseContext.update(ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE); @@ -424,7 +424,7 @@ BOOST_AUTO_TEST_CASE(TestCOMPORD) { BOOST_CHECK_NO_THROW( Schedule( deck , grid , fp, runspec, parseContext, errors, python )); parseContext.update( ParseContext::UNSUPPORTED_COMPORD_TYPE , InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW( Schedule( deck, grid , fp, runspec , parseContext, errors, python), std::invalid_argument ); + BOOST_CHECK_THROW( Schedule( deck, grid , fp, runspec , parseContext, errors, python), OpmInputError ); } @@ -441,7 +441,7 @@ BOOST_AUTO_TEST_CASE(TestNew) { BOOST_CHECK_EQUAL( false , parseContext.hasKey("NO")); parseContext.addKey("NEW_KEY", InputError::THROW_EXCEPTION); BOOST_CHECK_EQUAL( true , parseContext.hasKey("NEW_KEY")); - BOOST_CHECK_THROW( parseContext.get("NO") , std::invalid_argument ); + BOOST_CHECK_THROW( parseContext.get("NO") , std::invalid_argument); BOOST_CHECK_EQUAL( parseContext.get("NEW_KEY") , InputError::THROW_EXCEPTION ); parseContext.addKey("KEY2", InputError::THROW_EXCEPTION); BOOST_CHECK_EQUAL( parseContext.get("NEW_KEY") , InputError::THROW_EXCEPTION ); @@ -498,7 +498,7 @@ BOOST_AUTO_TEST_CASE( test_too_much_data ) { parseContext.update(ParseContext::PARSE_EXTRA_DATA , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deckString , parseContext, errors ) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deckString , parseContext, errors ) , OpmInputError); parseContext.update(ParseContext::PARSE_EXTRA_DATA , InputError::IGNORE ); auto deck = parser.parseString( deckString , parseContext, errors ); @@ -530,6 +530,12 @@ BOOST_AUTO_TEST_CASE( test_invalid_wtemplate_config ) { 1000*0.25 / TOPS 100*0.25 / + PERMX + 1000*1 / + PERMY + 1000*1 / + PERMZ + 1000*1 / SCHEDULE DATES -- 1 10 OKT 2008 / @@ -770,7 +776,7 @@ BOOST_AUTO_TEST_CASE( test_invalid_wtemplate_config ) { FieldPropsManager fp( deckUnSupported, Phases{true, true, true}, grid, table); Runspec runspec( deckUnSupported); - BOOST_CHECK_THROW( Schedule( deckUnSupported , grid , fp, runspec , parseContext, errors, python), std::invalid_argument ); + BOOST_CHECK_THROW( Schedule( deckUnSupported , grid , fp, runspec , parseContext, errors, python), OpmInputError); } } @@ -813,7 +819,7 @@ RPTRUNSPEC BOOST_CHECK( deck.hasKeyword("RPTRUNSP") ); context.update(ParseContext::PARSE_LONG_KEYWORD, InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW( parser.parseString(deck_string, context, error), std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString(deck_string, context, error), OpmInputError); } diff --git a/tests/parser/ParserIncludeTests.cpp b/tests/parser/ParserIncludeTests.cpp index df1ecf634..1657e2a85 100644 --- a/tests/parser/ParserIncludeTests.cpp +++ b/tests/parser/ParserIncludeTests.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -44,7 +45,7 @@ BOOST_AUTO_TEST_CASE(ParserKeyword_includeInvalid) { Opm::ErrorGuard errors; parseContext.update(Opm::ParseContext::PARSE_MISSING_INCLUDE , Opm::InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW(parser.parseFile(inputFilePath.string() , parseContext, errors) , std::invalid_argument); + BOOST_CHECK_THROW(parser.parseFile(inputFilePath.string() , parseContext, errors) , Opm::OpmInputError); parseContext.update(Opm::ParseContext::PARSE_MISSING_INCLUDE , Opm::InputError::IGNORE ); BOOST_CHECK_NO_THROW(parser.parseFile(inputFilePath.string() , parseContext, errors)); @@ -123,9 +124,9 @@ BOOST_AUTO_TEST_CASE(ParserKeyword_includeWrongCase) { Opm::ErrorGuard errors; parseContext.update(Opm::ParseContext::PARSE_MISSING_INCLUDE , Opm::InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW(parser.parseFile(inputFile1Path.string(), parseContext, errors), std::invalid_argument); - BOOST_CHECK_THROW(parser.parseFile(inputFile2Path.string(), parseContext, errors), std::invalid_argument); - BOOST_CHECK_THROW(parser.parseFile(inputFile3Path.string(), parseContext, errors), std::invalid_argument); + BOOST_CHECK_THROW(parser.parseFile(inputFile1Path.string(), parseContext, errors), Opm::OpmInputError); + BOOST_CHECK_THROW(parser.parseFile(inputFile2Path.string(), parseContext, errors), Opm::OpmInputError); + BOOST_CHECK_THROW(parser.parseFile(inputFile3Path.string(), parseContext, errors), Opm::OpmInputError); #else // for case-insensitive filesystems, the include statement will // always work regardless of how the capitalization of the diff --git a/tests/parser/ParserTests.cpp b/tests/parser/ParserTests.cpp index 7c42bb3f4..1b1b920e6 100644 --- a/tests/parser/ParserTests.cpp +++ b/tests/parser/ParserTests.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -323,7 +324,7 @@ BOOST_AUTO_TEST_CASE( PATHS_has_global_scope ) { parseContext.update( ParseContext::PARSE_MISSING_INCLUDE , Opm::InputError::THROW_EXCEPTION); const auto deck = parser.parseFile( prefix() + "parser/PATHSInInclude.data", parseContext, errors ); BOOST_CHECK(deck.hasKeyword("OIL")); - BOOST_CHECK_THROW( parser.parseFile( prefix() + "parser/PATHSInIncludeInvalid.data", parseContext, errors ), std::invalid_argument ); + BOOST_CHECK_THROW( parser.parseFile( prefix() + "parser/PATHSInIncludeInvalid.data", parseContext, errors ), OpmInputError ); } BOOST_AUTO_TEST_CASE( PATHS_with_backslashes ) { @@ -1226,10 +1227,10 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) { BOOST_CHECK_NO_THROW(parserRecord.parse(parseContext, errors, rawRecord, unit_system, unit_system, KeywordLocation())); RawRecord rawRecordOneExtra( "3 3 3 4 " ); - BOOST_CHECK_THROW(parserRecord.parse(parseContext, errors, rawRecordOneExtra, unit_system, unit_system, KeywordLocation()), std::invalid_argument); + BOOST_CHECK_THROW(parserRecord.parse(parseContext, errors, rawRecordOneExtra, unit_system, unit_system, KeywordLocation()), OpmInputError); RawRecord rawRecordForgotRecordTerminator( "3 3 3 \n 4 4 4 " ); - BOOST_CHECK_THROW(parserRecord.parse(parseContext, errors, rawRecordForgotRecordTerminator, unit_system, unit_system, KeywordLocation()), std::invalid_argument); + BOOST_CHECK_THROW(parserRecord.parse(parseContext, errors, rawRecordForgotRecordTerminator, unit_system, unit_system, KeywordLocation()), OpmInputError); } @@ -2333,7 +2334,7 @@ GUIDERATE )"; parseContext.update(ParseContext::PARSE_LONG_KEYWORD, Opm::InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW(parser.parseString(deck_string, parseContext, errors), std::invalid_argument); + BOOST_CHECK_THROW(parser.parseString(deck_string, parseContext, errors), OpmInputError); parseContext.update(ParseContext::PARSE_LONG_KEYWORD, Opm::InputError::IGNORE); auto deck = parser.parseString(deck_string, parseContext, errors); diff --git a/tests/parser/RestartConfigTests.cpp b/tests/parser/RestartConfigTests.cpp index a4f15e86a..07e9bdb40 100644 --- a/tests/parser/RestartConfigTests.cpp +++ b/tests/parser/RestartConfigTests.cpp @@ -405,7 +405,7 @@ BOOST_AUTO_TEST_CASE(RPTRST_mixed_mnemonics_int_list) { ErrorGuard errors; auto deck = Parser().parseString( data, parseContext, errors ); parseContext.update(ParseContext::RPT_MIXED_STYLE, InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW( RestartConfig( TimeMap(deck), deck, parseContext, errors ), std::invalid_argument); + BOOST_CHECK_THROW( RestartConfig( TimeMap(deck), deck, parseContext, errors ), OpmInputError); } BOOST_AUTO_TEST_CASE(RPTRST) { @@ -613,7 +613,7 @@ BOOST_AUTO_TEST_CASE(RPTRST_FORMAT_ERROR) { auto deck1 = parser.parseString( deckData1, ctx, errors ); ctx.update(ParseContext::RPT_UNKNOWN_MNEMONIC, InputError::IGNORE); ctx.update(ParseContext::RPT_MIXED_STYLE, InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW(RestartConfig(TimeMap(deck1), deck1, ctx, errors), std::invalid_argument); + BOOST_CHECK_THROW(RestartConfig(TimeMap(deck1), deck1, ctx, errors), OpmInputError); ctx.update(ParseContext::RPT_MIXED_STYLE, InputError::IGNORE); RestartConfig rstConfig1( TimeMap(deck1), deck1, ctx, errors ); @@ -644,7 +644,7 @@ BOOST_AUTO_TEST_CASE(RPTRST_FORMAT_ERROR) { auto deck2 = parser.parseString( deckData2, ctx, errors ); ctx.update(ParseContext::RPT_UNKNOWN_MNEMONIC, InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW(RestartConfig(TimeMap(deck2), deck2, ctx, errors), std::invalid_argument); + BOOST_CHECK_THROW(RestartConfig(TimeMap(deck2), deck2, ctx, errors), OpmInputError); ctx.update(ParseContext::RPT_UNKNOWN_MNEMONIC, InputError::IGNORE); RestartConfig rstConfig2( TimeMap(deck2), deck2, ctx, errors ); diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index 0e089550d..38486e25a 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -27,6 +27,7 @@ #include #include +#include #include @@ -1058,7 +1059,7 @@ BOOST_AUTO_TEST_CASE(createDeckWithWeltArgException) { "/\n"; - BOOST_CHECK_THROW(make_schedule(input), std::invalid_argument); + BOOST_CHECK_THROW(make_schedule(input), Opm::OpmInputError); } BOOST_AUTO_TEST_CASE(createDeckWithWeltArgException2) { @@ -1068,7 +1069,7 @@ BOOST_AUTO_TEST_CASE(createDeckWithWeltArgException2) { " OP_1 LRAT /\n" " OP_1 RESV 1801.05 /\n" "/\n"; - BOOST_CHECK_THROW(make_schedule(input), std::invalid_argument); + BOOST_CHECK_THROW(make_schedule(input), Opm::OpmInputError); } BOOST_AUTO_TEST_CASE(createDeckWithWPIMULT) { @@ -1181,7 +1182,7 @@ BOOST_AUTO_TEST_CASE(WELSPECS_WGNAME_SPACE) { ErrorGuard errors; parseContext.update(ParseContext::PARSE_WGNAME_SPACE, InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW( Opm::Schedule(deck, grid, fp, runspec, parseContext, errors, python), std::invalid_argument); + BOOST_CHECK_THROW( Opm::Schedule(deck, grid, fp, runspec, parseContext, errors, python), Opm::OpmInputError); parseContext.update(ParseContext::PARSE_WGNAME_SPACE, InputError::IGNORE); BOOST_CHECK_NO_THROW( Opm::Schedule(deck, grid, fp, runspec, parseContext, errors, python)); @@ -1804,7 +1805,7 @@ BOOST_AUTO_TEST_CASE(unsupportedOptionWHISTCTL) { TableManager table ( deck ); FieldPropsManager fp( deck, Phases{true, true, true}, grid, table); Runspec runspec (deck); - BOOST_CHECK_THROW(Schedule(deck, grid, fp, runspec, python), std::invalid_argument); + BOOST_CHECK_THROW(Schedule(deck, grid, fp, runspec, python), Opm::OpmInputError); } BOOST_AUTO_TEST_CASE(move_HEAD_I_location) { diff --git a/tests/parser/SummaryConfigTests.cpp b/tests/parser/SummaryConfigTests.cpp index d763c013f..19d904977 100644 --- a/tests/parser/SummaryConfigTests.cpp +++ b/tests/parser/SummaryConfigTests.cpp @@ -21,6 +21,7 @@ #include +#include #include #include #include @@ -300,7 +301,7 @@ BOOST_AUTO_TEST_CASE(region2region) { names.begin(), names.end() ); parseContext.update(ParseContext::SUMMARY_UNHANDLED_KEYWORD, InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW( createSummary(input, parseContext), std::invalid_argument); + BOOST_CHECK_THROW( createSummary(input, parseContext), OpmInputError); } BOOST_AUTO_TEST_CASE(completions) { @@ -449,7 +450,7 @@ BOOST_AUTO_TEST_CASE(INVALID_WELL1) { "NEW-WELL /\n" "/\n"; parseContext.updateKey( ParseContext::SUMMARY_UNKNOWN_WELL , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( createSummary( input , parseContext ) , std::invalid_argument); + BOOST_CHECK_THROW( createSummary( input , parseContext ) , OpmInputError); parseContext.updateKey( ParseContext::SUMMARY_UNKNOWN_WELL , InputError::IGNORE ); BOOST_CHECK_NO_THROW( createSummary( input , parseContext )); @@ -461,7 +462,7 @@ BOOST_AUTO_TEST_CASE(INVALID_WELL2) { const auto input = "WWCT\n" " NEW-WELL /\n"; parseContext.updateKey( ParseContext::SUMMARY_UNKNOWN_WELL , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( createSummary( input , parseContext ) , std::invalid_argument); + BOOST_CHECK_THROW( createSummary( input , parseContext ) , OpmInputError); parseContext.updateKey( ParseContext::SUMMARY_UNKNOWN_WELL , InputError::IGNORE ); BOOST_CHECK_NO_THROW( createSummary( input , parseContext )); @@ -472,7 +473,7 @@ BOOST_AUTO_TEST_CASE(UNDEFINED_UDQ_WELL) { const auto input = "WUWCT\n" "/\n"; parseContext.updateKey( ParseContext::SUMMARY_UNDEFINED_UDQ, InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( createSummary( input , parseContext ) , std::invalid_argument); + BOOST_CHECK_THROW( createSummary( input , parseContext ) , OpmInputError); parseContext.updateKey( ParseContext::SUMMARY_UNDEFINED_UDQ, InputError::IGNORE ); BOOST_CHECK_NO_THROW( createSummary( input , parseContext )); @@ -486,7 +487,7 @@ BOOST_AUTO_TEST_CASE(INVALID_GROUP) { const auto input = "GWCT\n" " NEW-GR /\n"; parseContext.updateKey( ParseContext::SUMMARY_UNKNOWN_GROUP , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( createSummary( input , parseContext ) , std::invalid_argument); + BOOST_CHECK_THROW( createSummary( input , parseContext ) , OpmInputError); parseContext.updateKey( ParseContext::SUMMARY_UNKNOWN_GROUP , InputError::IGNORE ); BOOST_CHECK_NO_THROW( createSummary( input , parseContext )); @@ -619,7 +620,7 @@ WOPRL ParseContext parseContext; parseContext.update(ParseContext::SUMMARY_UNHANDLED_KEYWORD, InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW(createSummary( input, parseContext ), std::invalid_argument); + BOOST_CHECK_THROW(createSummary( input, parseContext ), OpmInputError); parseContext.update(ParseContext::SUMMARY_UNHANDLED_KEYWORD, InputError::IGNORE); BOOST_CHECK_NO_THROW( createSummary(input, parseContext )); } diff --git a/tests/parser/UDQTests.cpp b/tests/parser/UDQTests.cpp index 7bf950aac..6db9576c4 100644 --- a/tests/parser/UDQTests.cpp +++ b/tests/parser/UDQTests.cpp @@ -17,6 +17,7 @@ Copyright 2018 Statoil ASA. #include #include +#include #include #include #include @@ -155,12 +156,12 @@ BOOST_AUTO_TEST_CASE(TEST) This expression has a well set as target type, and involves group with wildcard that is not supported by flow. */ - BOOST_CHECK_THROW( UDQDefine(udqp, "WUWI2", location, {"GOPR", "G*", "*", "2.0"}), std::logic_error); + BOOST_CHECK_THROW( UDQDefine(udqp, "WUWI2", location, {"GOPR", "G*", "*", "2.0"}), OpmInputError); /* UDQVarType == BLOCK is not yet supported. */ - BOOST_CHECK_THROW( UDQDefine(udqp, "WUWI2", location, {"BPR", "1","1", "1", "*", "2.0"}), std::logic_error); + BOOST_CHECK_THROW( UDQDefine(udqp, "WUWI2", location, {"BPR", "1","1", "1", "*", "2.0"}), OpmInputError); } @@ -1284,7 +1285,7 @@ BOOST_AUTO_TEST_CASE(UDQ_PARSE_ERROR) { } parseContext.update(ParseContext::UDQ_PARSE_ERROR, InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW( UDQDefine(udqp, "WUBHP", location, tokens, parseContext, errors), std::invalid_argument); + BOOST_CHECK_THROW( UDQDefine(udqp, "WUBHP", location, tokens, parseContext, errors), OpmInputError); } BOOST_AUTO_TEST_CASE(UDQ_TYPE_ERROR) { @@ -1318,7 +1319,7 @@ BOOST_AUTO_TEST_CASE(UDQ_TYPE_ERROR) { parseContext.update(ParseContext::UDQ_TYPE_ERROR, InputError::THROW_EXCEPTION); // This fails because the well expression (WBHP + 1) is assigned to the field variable FUBHP - BOOST_CHECK_THROW( UDQDefine(udqp, "FUBHP", location, tokens1, parseContext, errors), std::invalid_argument); + BOOST_CHECK_THROW( UDQDefine(udqp, "FUBHP", location, tokens1, parseContext, errors), OpmInputError); } diff --git a/tests/parser/data/integration_tests/someobscureelements.data b/tests/parser/data/integration_tests/someobscureelements.data deleted file mode 100644 index 1af06826d..000000000 --- a/tests/parser/data/integration_tests/someobscureelements.data +++ /dev/null @@ -1,15 +0,0 @@ --- Comment -OIL - -GRIDUNIT -METRES / - -GRUDINT -- A wrong, or unknown keyword - "text" 3 5 / - 3 3 3 3 3 3 / -/ - - - -RADFIN4 - 'NAME' 213 123 123 123 7 7 18 18 18 18 / diff --git a/tests/parser/integration/IntegrationTests.cpp b/tests/parser/integration/IntegrationTests.cpp index f9ca1d3d7..b99c578e1 100644 --- a/tests/parser/integration/IntegrationTests.cpp +++ b/tests/parser/integration/IntegrationTests.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -198,7 +199,24 @@ BOOST_AUTO_TEST_CASE(parse_fileWithBPRKeyword_dataiscorrect) { /***************** Testing non-recognized keywords ********************/ BOOST_AUTO_TEST_CASE(parse_unknownkeyword_exceptionthrown) { Parser parser; - BOOST_CHECK_THROW( parser.parseFile(pathprefix() + "someobscureelements.data"), std::invalid_argument); + std::string deck = R"( +-- Comment +OIL + +GRIDUNIT +METRES / + +GRUDINT -- A wrong, or unknown keyword + "text" 3 5 / + 3 3 3 3 3 3 / +/ + + + +RADFIN4 + 'NAME' 213 123 123 123 7 7 18 18 18 18 / +)"; + BOOST_CHECK_THROW( parser.parseString(deck), OpmInputError); } /*********************Testing truncated (default) records ***************************/ @@ -207,7 +225,18 @@ BOOST_AUTO_TEST_CASE(parse_unknownkeyword_exceptionthrown) { // Datafile contains 3 RADFIN4 keywords. One fully specified, one with 2 out of 11 items, and one with no items. BOOST_AUTO_TEST_CASE(parse_truncatedrecords_deckFilledWithDefaults) { Parser parser; - auto deck = parser.parseFile(pathprefix() + "truncated_records.data"); + std::string deck_string = R"( +-- Comment +OIL + +RADFIN4 +'NAME' 213 123 123 123 7 7 18 18 18 18 / + +RADFIN4 +'NAME' 213 123 123 123 7 7 18 18 18 / +)"; + + auto deck = parser.parseString(deck_string); BOOST_CHECK_EQUAL(3U, deck.size()); const auto& radfin4_0_full= deck.getKeyword("RADFIN4", 0); const auto& radfin4_1_partial= deck.getKeyword("RADFIN4", 1); diff --git a/tests/parser/integration/ParseKEYWORD.cpp b/tests/parser/integration/ParseKEYWORD.cpp index 63b115ec5..a5cefd1dd 100644 --- a/tests/parser/integration/ParseKEYWORD.cpp +++ b/tests/parser/integration/ParseKEYWORD.cpp @@ -20,6 +20,7 @@ #define BOOST_TEST_MODULE ParserKeywordsIntegrationTests #include +#include #include #include #include @@ -216,10 +217,10 @@ BOOST_AUTO_TEST_CASE( SORWMIS ) { Parser parser; // missing miscible keyword - BOOST_CHECK_THROW (parser.parseString(sorwmisData), std::invalid_argument ); + BOOST_CHECK_THROW (parser.parseString(sorwmisData), OpmInputError ); //too many tables - BOOST_CHECK_THROW( parser.parseString(miscibleTightData + sorwmisData), std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString(miscibleTightData + sorwmisData), OpmInputError); auto deck1 = parser.parseString(miscibleData + sorwmisData); diff --git a/tests/test_ArrayDimChecker.cpp b/tests/test_ArrayDimChecker.cpp index 4ffc4fab2..52fcab032 100644 --- a/tests/test_ArrayDimChecker.cpp +++ b/tests/test_ArrayDimChecker.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -430,7 +431,7 @@ BOOST_AUTO_TEST_CASE(WellDims) BOOST_CHECK_THROW( Opm::checkConsistentArrayDimensions(cse.es , cse.sched, parseContext, cse.guard), - std::invalid_argument); + Opm::OpmInputError); setWellDimsContext(Opm::InputError::DELAYED_EXIT1, parseContext); Opm::checkConsistentArrayDimensions(cse.es , cse.sched, @@ -467,7 +468,7 @@ BOOST_AUTO_TEST_CASE(WellDims_ManyChildGroups) // There *should* be errors from dimension checking BOOST_CHECK_THROW( Opm::checkConsistentArrayDimensions(cse.es , cse.sched, parseContext, cse.guard), - std::invalid_argument); + Opm::OpmInputError); setWellDimsContext(Opm::InputError::DELAYED_EXIT1, parseContext); Opm::checkConsistentArrayDimensions(cse.es , cse.sched,