From e42af7c0665fed814828b0ae7edbfc4350d57e13 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Thu, 13 Dec 2012 13:57:49 -0500 Subject: [PATCH] fc::error_report to fc::exception_ptr to enable inter-thread, inter-process error reports --- include/fc/error_report.hpp | 5 ++++- include/fc/exception.hpp | 2 +- src/error_report.cpp | 4 ++++ src/json_rpc_connection.cpp | 10 ++++------ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/fc/error_report.hpp b/include/fc/error_report.hpp index cd91a61..7822018 100644 --- a/include/fc/error_report.hpp +++ b/include/fc/error_report.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace fc { @@ -49,15 +50,17 @@ namespace fc { fc::string to_string()const; fc::string to_detail_string()const; error_context stack; ///< Human readable stack of what we were atempting to do. + + fc::exception_ptr copy_exception(); }; + } // namespace fc #include FC_REFLECT( fc::error_frame, (desc)(file)(line)(method)(time)(meta) ) FC_REFLECT( fc::error_report, (stack) ) -#include #define FC_REPORT( X, ... ) fc::error_report X( __FILE__, __LINE__, __func__, __VA_ARGS__ ) #define FC_THROW_REPORT( ... ) FC_THROW( fc::error_report( __FILE__, __LINE__, __func__, __VA_ARGS__ )) #define FC_REPORT_CURRENT(ER, ... ) (ER).pop_frame().push_frame( __FILE__, __LINE__, __func__, __VA_ARGS__ ) diff --git a/include/fc/exception.hpp b/include/fc/exception.hpp index b7d9fd2..3b4fc55 100644 --- a/include/fc/exception.hpp +++ b/include/fc/exception.hpp @@ -48,7 +48,7 @@ namespace fc { try { throw e; } catch (...) { return current_exception(); } return exception_ptr(); } - void rethrow_exception( const exception_ptr& e ); + void rethrow_exception( const exception_ptr& e ); void throw_exception( const char* func, const char* file, int line, const char* msg ); void throw_exception_( const char* func, const char* file, int line, const char* msg, diff --git a/src/error_report.cpp b/src/error_report.cpp index 7df1b09..4a817e9 100644 --- a/src/error_report.cpp +++ b/src/error_report.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace fc { error_frame::error_frame( const fc::string& f, uint64_t l, const fc::string& m, const fc::string& d, fc::value met ) @@ -137,5 +138,8 @@ fc::string error_report::to_detail_string()const { } return ss.str(); } +fc::exception_ptr error_report::copy_exception() { + return boost::copy_exception(*this); +} } // namespace fc diff --git a/src/json_rpc_connection.cpp b/src/json_rpc_connection.cpp index 6f00d0b..f790e8f 100644 --- a/src/json_rpc_connection.cpp +++ b/src/json_rpc_connection.cpp @@ -106,13 +106,11 @@ namespace fc { namespace json { } else { auto e_itr = v.find( "error" ); if( e_itr != end ) { - cur->set_exception( - fc::copy_exception( - fc::generic_exception( - value_cast( - e_itr->val["message"] ) ) ) ); + cur->set_exception( fc::value_cast(e_itr->val["data"]).copy_exception() ); + } else { + elog( "no result nor error field" ); } - } + } } catch( ... ) { cur->set_exception( fc::current_exception() ); }