From d729816b06651ccde50940c92db729cf9fb4c61e Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 18 Sep 2019 12:51:17 +0200 Subject: [PATCH 1/6] Changes to avoid conflict in following cherry-pick --- src/exception.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/exception.cpp b/src/exception.cpp index d3fadbb99..cc930090c 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -182,11 +182,11 @@ namespace fc */ string exception::to_detail_string( log_level ll )const { - fc::stringstream ss; + std::stringstream ss; ss << variant(my->_code).as_string() <<" " << my->_name << ": " <_what<<"\n"; for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ) { - ss << itr->get_message() <<"\n"; + ss << itr->get_message() <<"\n"; //fc::format_string( itr->get_format(), itr->get_data() ) <<"\n"; try { ss << " " << json::to_string( itr->get_data() )<<"\n"; @@ -207,12 +207,12 @@ namespace fc */ string exception::to_string( log_level ll )const { - fc::stringstream ss; - ss << what() << ":"; + std::stringstream ss; + ss << what() << " (" << variant(my->_code).as_string() <<")\n"; for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ++itr ) { - if( itr->get_format().size() ) - ss << " " << fc::format_string( itr->get_format(), itr->get_data() ); + ss << fc::format_string( itr->get_format(), itr->get_data() ) << "\n"; + // ss << " " << itr->get_context().to_string() <<"\n"; } return ss.str(); } From 2eb047a6f4d61704478376a88f12205fe12dde69 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 22 May 2018 10:59:42 -0400 Subject: [PATCH 2/6] Add exception handling to to_string and to_detail_string --- src/exception.cpp | 48 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/exception.cpp b/src/exception.cpp index cc930090c..bc72783da 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -183,9 +183,17 @@ namespace fc string exception::to_detail_string( log_level ll )const { std::stringstream ss; - ss << variant(my->_code).as_string() <<" " << my->_name << ": " <_what<<"\n"; - for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ) - { + try { + try { + ss << variant( my->_code ).as_string(); + } catch( std::bad_alloc& ) { + throw; + } catch( ... ) { + ss << "<- exception in to_detail_string."; + } + ss << " " << my->_name << ": " << my->_what << "\n"; + for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ) { + try { ss << itr->get_message() <<"\n"; //fc::format_string( itr->get_format(), itr->get_data() ) <<"\n"; try { @@ -197,8 +205,18 @@ namespace fc } ss << " " << itr->get_context().to_string(); ++itr; + } catch( std::bad_alloc& ) { + throw; + } catch( ... ) { + ss << "<- exception in to_detail_string."; + } if( itr != my->_elog.end() ) ss<<"\n"; } + } catch( std::bad_alloc& ) { + throw; + } catch( ... ) { + ss << "<- exception in to_detail_string.\n"; + } return ss.str(); } @@ -208,13 +226,31 @@ namespace fc string exception::to_string( log_level ll )const { std::stringstream ss; - ss << what() << " (" << variant(my->_code).as_string() <<")\n"; - for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ++itr ) - { + try { + ss << my->_what; + try { + ss << " (" << variant( my->_code ).as_string() << ")\n"; + } catch( std::bad_alloc& ) { + throw; + } catch( ... ) { + ss << "<- exception in to_string.\n"; + } + for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ++itr ) { + try { ss << fc::format_string( itr->get_format(), itr->get_data() ) << "\n"; // ss << " " << itr->get_context().to_string() <<"\n"; + } catch( std::bad_alloc& ) { + throw; + } catch( ... ) { + ss << "<- exception in to_string.\n"; + } } return ss.str(); + } catch( std::bad_alloc& ) { + throw; + } catch( ... ) { + ss << "<- exception in to_string.\n"; + } } [[noreturn]] void exception_factory::rethrow( const exception& e )const From 3583ee613887698d695e1159d6e6a839bdb25cf7 Mon Sep 17 00:00:00 2001 From: Spartucus Date: Wed, 30 May 2018 17:56:20 +0800 Subject: [PATCH 3/6] Fix non-void function return value Since last catch insert exception string to `ss`, it should returns. --- src/exception.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/exception.cpp b/src/exception.cpp index bc72783da..8814f53ea 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -251,6 +251,7 @@ namespace fc } catch( ... ) { ss << "<- exception in to_string.\n"; } + return ss.str(); } [[noreturn]] void exception_factory::rethrow( const exception& e )const From 5b8a7c281c35ec57bd080d55dad120ddc901fee9 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 18 Sep 2019 13:04:24 +0200 Subject: [PATCH 4/6] Partial revert "Changes to avoid conflict in following cherry-pick" This reverts commit d729816b06651ccde50940c92db729cf9fb4c61e. --- src/exception.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/exception.cpp b/src/exception.cpp index 8814f53ea..81cc58509 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -194,7 +194,7 @@ namespace fc ss << " " << my->_name << ": " << my->_what << "\n"; for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ) { try { - ss << itr->get_message() <<"\n"; //fc::format_string( itr->get_format(), itr->get_data() ) <<"\n"; + ss << itr->get_message() <<"\n"; try { ss << " " << json::to_string( itr->get_data() )<<"\n"; @@ -227,18 +227,11 @@ namespace fc { std::stringstream ss; try { - ss << my->_what; - try { - ss << " (" << variant( my->_code ).as_string() << ")\n"; - } catch( std::bad_alloc& ) { - throw; - } catch( ... ) { - ss << "<- exception in to_string.\n"; - } + ss << what() << ":"; for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ++itr ) { + if( itr->get_format().size() ) try { - ss << fc::format_string( itr->get_format(), itr->get_data() ) << "\n"; - // ss << " " << itr->get_context().to_string() <<"\n"; + ss << " " << fc::format_string( itr->get_format(), itr->get_data() ); } catch( std::bad_alloc& ) { throw; } catch( ... ) { From 164f1f68e62432b32b1838a6e662cdf8a57f1536 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 18 Sep 2019 13:06:46 +0200 Subject: [PATCH 5/6] Whitespace fixes --- src/exception.cpp | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/exception.cpp b/src/exception.cpp index 81cc58509..bd04f8e77 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -192,26 +192,27 @@ namespace fc ss << "<- exception in to_detail_string."; } ss << " " << my->_name << ": " << my->_what << "\n"; - for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ) { - try { - ss << itr->get_message() <<"\n"; - try - { - ss << " " << json::to_string( itr->get_data() )<<"\n"; - } - catch( const fc::assert_exception& e ) + for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ) { - ss << "ERROR: Failed to convert log data to string!\n"; - } - ss << " " << itr->get_context().to_string(); - ++itr; + try { + ss << itr->get_message() <<"\n"; + try + { + ss << " " << json::to_string( itr->get_data() )<<"\n"; + } + catch( const fc::assert_exception& e ) + { + ss << "ERROR: Failed to convert log data to string!\n"; + } + ss << " " << itr->get_context().to_string(); + ++itr; } catch( std::bad_alloc& ) { throw; } catch( ... ) { ss << "<- exception in to_detail_string."; } - if( itr != my->_elog.end() ) ss<<"\n"; - } + if( itr != my->_elog.end() ) ss<<"\n"; + } } catch( std::bad_alloc& ) { throw; } catch( ... ) { @@ -230,14 +231,14 @@ namespace fc ss << what() << ":"; for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ++itr ) { if( itr->get_format().size() ) - try { - ss << " " << fc::format_string( itr->get_format(), itr->get_data() ); - } catch( std::bad_alloc& ) { - throw; - } catch( ... ) { - ss << "<- exception in to_string.\n"; - } - } + try { + ss << " " << fc::format_string( itr->get_format(), itr->get_data() ); + } catch( std::bad_alloc& ) { + throw; + } catch( ... ) { + ss << "<- exception in to_string.\n"; + } + } return ss.str(); } catch( std::bad_alloc& ) { throw; From 20c16882235de2d5f6a366252fea6a889d417e76 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 18 Sep 2019 13:07:01 +0200 Subject: [PATCH 6/6] Removed superfluous return --- src/exception.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/exception.cpp b/src/exception.cpp index bd04f8e77..01d2615ad 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -239,7 +239,6 @@ namespace fc ss << "<- exception in to_string.\n"; } } - return ss.str(); } catch( std::bad_alloc& ) { throw; } catch( ... ) {