Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectPath XML errors feedback #2341

Merged
merged 27 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
593046d
No more crash when PackCollection::objectPath is wrong
MelReyCG Mar 15, 2023
cb89711
- Fixing getPath() so it starts with "/" instead of "m/"
MelReyCG Mar 15, 2023
b734b49
Made group searching errors clearer.
MelReyCG Mar 15, 2023
8d95760
- Improved FieldSpecification::objectPath errors clarity
MelReyCG Mar 15, 2023
cae0f90
Added a test for Group path methods and data hierarchy
MelReyCG Mar 16, 2023
a1f322e
indentation fix
MelReyCG Mar 16, 2023
2eff3e3
testMeshObjectPath now expect exceptions instead of errors
MelReyCG Mar 16, 2023
5528732
Merge remote-tracking branch 'origin/develop' into bugfix/rey/2320-xm…
MelReyCG Mar 16, 2023
f737cca
Added some doxygen throwing documentation
MelReyCG Mar 17, 2023
5ba1d88
fix : forgot to use a reference
MelReyCG Mar 17, 2023
ed942e3
Merge remote-tracking branch 'origin/develop' into bugfix/rey/2320-xm…
MelReyCG Mar 17, 2023
f165806
getPath() call on Problem node now returns "/"
MelReyCG Mar 23, 2023
a67ae55
shorter messages
MelReyCG Mar 23, 2023
9430d8f
code style & reformulations
MelReyCG Mar 28, 2023
74f3c18
Docs rewording
MelReyCG Mar 28, 2023
52309be
- modified messages after user feedback.
MelReyCG Mar 29, 2023
d0bdbbb
- code style
MelReyCG Mar 31, 2023
1912e66
variable naming
MelReyCG Apr 3, 2023
930dd64
updating "invalid MeshBody" error message.
MelReyCG Apr 3, 2023
aa9a930
Test to check the exception of getGroupByPath()
MelReyCG Apr 3, 2023
026b433
code style
MelReyCG Apr 3, 2023
7fb5afb
- Added a stringutilities::cstrlen (= compile-time strlen)
MelReyCG Apr 5, 2023
3fc7414
fixing a wrong namespace
MelReyCG Apr 6, 2023
97fd7e0
added c++17 comment
MelReyCG Apr 6, 2023
70abf6c
Code factorisation (THROW_IF)
MelReyCG Apr 13, 2023
23213e7
Merge branch 'develop' into bugfix/rey/2320-xml-errors-feedback
MelReyCG Apr 19, 2023
f9f3c73
GEOSX -> GEOS
MelReyCG Apr 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/coreComponents/common/Logger.cpp
MelReyCG marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ std::string InputError::InsertExMsg( std::string const & originalMsg, std::strin

size_t insertPos = 0;
// for readability purposes, we try to insert the message after the "***** Rank N: " or after "***** " instead of at the top.
static auto constexpr rankLogStartStr = "***** Rank ";
static auto constexpr rankLogEndStr = ": ";
static auto constexpr simpleLogStartStr = "***** ";
if( ( insertPos = newMsg.find( rankLogStartStr ) ) != std::string::npos )
static auto constexpr rankLogStart = "***** Rank ";
static auto constexpr rankLogEnd = ": ";
static auto constexpr simpleLogStart = "***** ";
if( ( insertPos = newMsg.find( rankLogStart ) ) != std::string::npos )
{
insertPos = newMsg.find( rankLogEndStr, insertPos + strlen( rankLogStartStr ) ) + strlen( rankLogEndStr );
insertPos = newMsg.find( rankLogEnd, insertPos + strlen( rankLogStart ) ) + strlen( rankLogEnd );
}
else if( ( insertPos = newMsg.find_last_of( simpleLogStartStr ) ) != std::string::npos )
else if( ( insertPos = newMsg.find_last_of( simpleLogStart ) ) != std::string::npos )
{
insertPos += strlen( simpleLogStartStr );
insertPos += strlen( simpleLogStart );
}
newMsg.insert( insertPos, msgToInsert );

Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/common/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ struct InputError : public std::runtime_error
/**
* @brief Returns an exception message in which we insert another message.
*/
static std::string InsertExMsg( std::string const & originalMsg, std::string const & msgToInsert );
std::string InsertExMsg( std::string const & originalMsg, std::string const & msgToInsert );
MelReyCG marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down
33 changes: 22 additions & 11 deletions src/coreComponents/mesh/MeshObjectPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,36 @@ MeshObjectPath::fillPathTokens( string const & path,
{
pathTokens.insert( pathTokens.begin(), "{*}" );

string existingMeshBodyAndLevel;
// searching if the mesh level exists
bool levelNameFound = false;
meshBodies.forSubGroups< MeshBody >( [&]( MeshBody const & meshBody )
{
existingMeshBodyAndLevel += meshBody.getName() + ": ";
meshBody.forMeshLevels( [&]( MeshLevel const & meshLevel )
{
existingMeshBodyAndLevel += meshLevel.getName() + ", ";
levelNameFound = ( unidentifiedName==meshLevel.getName() ) ? true : levelNameFound;
levelNameFound |= ( unidentifiedName==meshLevel.getName() );
} );
existingMeshBodyAndLevel += "/n";
} );

GEOSX_THROW_IF( !levelNameFound,
GEOSX_FMT( "Path {} specifies an invalid MeshBody or MeshLevel. ",
"existing MeshBodies: {} /n",
path,
existingMeshBodyAndLevel ),
InputError );
if( !levelNameFound )
{
string existingMeshBodiesAndLevels;
meshBodies.forSubGroups< MeshBody >( [&]( MeshBody const & meshBody )
{
std::vector< string > meshLevelsNames;
existingMeshBodiesAndLevels += " MeshBody "+meshBody.getName() + ": { ";
meshBody.forMeshLevels( [&]( MeshLevel const & meshLevel )
{
meshLevelsNames.push_back( meshLevel.getName() );
} );
existingMeshBodiesAndLevels += stringutilities::join( meshLevelsNames, ", " ) + " }\n";
} );

GEOSX_THROW( GEOSX_FMT( "Path {0} specifies an invalid MeshBody or MeshLevel. ",
"existing MeshBodies: \n{1}\n",
path,
existingMeshBodiesAndLevels ),
InputError );
}
pathTokens.insert( pathTokens.begin()+1, unidentifiedName );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ TEST( testGroupPath, testGlobalPaths )
Group const & group = problem.getGroupByPath( path );
ASSERT_STREQ( path.c_str(), group.getPath().c_str() );
}

// test for a wrong path given to getGroupByPath()
bool trowHappened = false;
try
{
problem.getGroupByPath( "/Mesh/mesh2" );
}
catch( const std::domain_error & e )
{
static constexpr auto expectedMsg = "***** Controlling expression (should be false): true\n"
"***** Rank 0: Group /Mesh has no child named mesh2\n"
"The children of Mesh are: { mesh1 }";
// checks if the exception contains the expected message
ASSERT_TRUE( string( e.what() ).find( expectedMsg ) != string::npos );
trowHappened = true;
}
// checks if the exception has been thrown as expected
ASSERT_TRUE( trowHappened );
}

int main( int argc, char * * argv )
Expand Down