Skip to content

Commit

Permalink
Do not print stats about each resource if the whole archive failed to…
Browse files Browse the repository at this point in the history
… open
  • Loading branch information
VeaaC committed Jun 20, 2024
1 parent 2df1b1e commit 0c9aa96
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 50 deletions.
12 changes: 7 additions & 5 deletions flatdata-cpp/src/Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,27 @@ Archive::describe( size_t nest_level ) const
if ( is_root_node )
{
result << hline << "FATAL: Resource storage not initialized. Please check archive path."
<< newl;
<< newl << hline;
}
else
{
result << "Uninitialized Archive " << name( );
result << "Uninitialized Archive " << name( ) << newl;
}
return result.str( );
}

if ( m_storage && !m_signature )
if ( !m_signature )
{
result << ( is_root_node ? hline : empty )
<< "FATAL: Archive signature does not match software expectations."
<< ( is_root_node ? newl : empty ) << hline;
result << compute_diff(
schema( ),
m_storage->read_schema( internal::signature_name( name( ) ).c_str( ) ).char_ptr( ) );
return result.str( );
}

if ( m_storage && !m_is_open )
if ( !m_is_open )
{
// Error propagated to root and storage is not initialized in respective child. No root
// check needed.
Expand All @@ -282,7 +284,7 @@ Archive::describe( size_t nest_level ) const
{
const std::string indent( ( nest_level - 1 ) * TAB_WIDTH, ' ' );
result << newl + indent + std::string( "|" ) + newl + indent + std::string( "|->" )
<< " Flatdata Archive: " << name( ) << std::endl;
<< " Flatdata Archive: " << name( ) << newl;
}

describe_resources( result, nest_level );
Expand Down
2 changes: 2 additions & 0 deletions flatdata-cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ target_include_directories(flatdata_test
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../vendor
)

target_compile_definitions(flatdata_test PRIVATE CATCH_CONFIG_CONSOLE_WIDTH=120)

target_link_libraries(flatdata_test
flatdata
${CMAKE_THREAD_LIBS_INIT}
Expand Down
81 changes: 36 additions & 45 deletions flatdata-cpp/test/GeneratedArchiveTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,6 @@ Resource Optional Too Large Loaded Details
outer1 NO NO YES Structure of size 1
outer2 NO NO YES Structure of size 1
inner NO NO NO Uninitialized Archive InnerArchive
|
|-> Flatdata Archive: InnerArchive
inner NO NO NO Uninitialized Structure AStruct
================================================================================
)data";

Expand Down Expand Up @@ -395,9 +392,44 @@ Resource Optional Too Large Loaded Details
================================================================================
outer NO NO YES Structure of size 1
archive_resource YES NO NO Uninitialized Archive InnerArchive
================================================================================
)data";

REQUIRE( outer.describe( ) == expected );
}

TEMPLATE_TEST_CASE_METHOD(
Fixture, "Sub-archives are described", "[GeneratedArchive]", std::true_type, std::false_type )
{
{
auto outer_builder = OuterArchiveBuilder::open( Fixture< TestType >::storage );
CHECK( outer_builder );

flatdata::Struct< AStruct > o;
outer_builder.set_outer1( *o );
outer_builder.set_outer2( *o );

auto inner_builder = outer_builder.inner( );
CHECK( inner_builder );
inner_builder.set_inner( *o );
}

auto outer = OuterArchive::open( Fixture< TestType >::storage );
REQUIRE( outer.is_open( ) );
REQUIRE( outer.inner( ).is_open( ) );

const char* const expected
= R"data(================================================================================
Flatdata Archive: OuterArchive
================================================================================
Resource Optional Too Large Loaded Details
================================================================================
outer1 NO NO YES Structure of size 1
outer2 NO NO YES Structure of size 1
inner NO NO YES
|
|-> Flatdata Archive: InnerArchive
inner NO NO NO Uninitialized Structure AStruct
inner NO NO YES Structure of size 1
================================================================================
)data";

Expand Down Expand Up @@ -531,16 +563,6 @@ TEST_CASE( "Describe ouputs fatal errors", "[GeneratedArchive]" )
R"data(================================================================================
FATAL: Resource storage not initialized. Please check archive path.
================================================================================
Flatdata Archive: SimpleResources
================================================================================
Resource Optional Too Large Loaded Details
================================================================================
object_resource NO NO NO Uninitialized Structure AStruct
vector_resource NO NO NO Uninitialized Array
multivector_resource NO NO NO Uninitialized MultiArray
raw_data_resource NO NO NO Uninitialized Raw data
optional_resource YES NO NO Uninitialized Raw data
================================================================================
)data";

REQUIRE( archive.describe( ) == expected );
Expand Down Expand Up @@ -604,24 +626,6 @@ FATAL: Archive signature does not match software expectations.
"}"
"}"
...
================================================================================
FATAL: Archive initialization failed. Failed loading mandatory resources.
================================================================================
Flatdata Archive: OutermostArchive
================================================================================
Resource Optional Too Large Loaded Details
================================================================================
outermost NO NO NO Uninitialized Structure AStruct
outer NO NO NO Uninitialized Archive OuterArchive
|
|-> Flatdata Archive: OuterArchive
outer1 NO NO NO Uninitialized Structure AStruct
outer2 NO NO NO Uninitialized Structure AStruct
inner NO NO NO Uninitialized Archive InnerArchive
|
|-> Flatdata Archive: InnerArchive
inner NO NO NO Uninitialized Structure AStruct
================================================================================
)";
REQUIRE( description == expectation );
}
Expand Down Expand Up @@ -668,19 +672,6 @@ FATAL: Archive signature does not match software expectations.
"}"
"}"
...
================================================================================
FATAL: Archive initialization failed. Failed loading mandatory resources.
================================================================================
Flatdata Archive: OuterWithOptional
================================================================================
Resource Optional Too Large Loaded Details
================================================================================
outer NO NO NO Uninitialized Structure AStruct
archive_resource YES NO NO Uninitialized Archive InnerArchive
|
|-> Flatdata Archive: InnerArchive
inner NO NO NO Uninitialized Structure AStruct
================================================================================
)";
REQUIRE( description == expectation );
}
Expand Down

0 comments on commit 0c9aa96

Please sign in to comment.