fc::error_report to fc::exception_ptr to enable inter-thread, inter-process error reports

This commit is contained in:
Daniel Larimer 2012-12-13 13:57:49 -05:00
parent cf10bac3db
commit e42af7c066
4 changed files with 13 additions and 8 deletions

View file

@ -3,6 +3,7 @@
#include <fc/string.hpp> #include <fc/string.hpp>
#include <fc/value.hpp> #include <fc/value.hpp>
#include <fc/optional.hpp> #include <fc/optional.hpp>
#include <fc/exception.hpp>
namespace fc { namespace fc {
@ -49,15 +50,17 @@ namespace fc {
fc::string to_string()const; fc::string to_string()const;
fc::string to_detail_string()const; fc::string to_detail_string()const;
error_context stack; ///< Human readable stack of what we were atempting to do. error_context stack; ///< Human readable stack of what we were atempting to do.
fc::exception_ptr copy_exception();
}; };
} // namespace fc } // namespace fc
#include <fc/reflect.hpp> #include <fc/reflect.hpp>
FC_REFLECT( fc::error_frame, (desc)(file)(line)(method)(time)(meta) ) FC_REFLECT( fc::error_frame, (desc)(file)(line)(method)(time)(meta) )
FC_REFLECT( fc::error_report, (stack) ) FC_REFLECT( fc::error_report, (stack) )
#include <fc/exception.hpp>
#define FC_REPORT( X, ... ) fc::error_report X( __FILE__, __LINE__, __func__, __VA_ARGS__ ) #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_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__ ) #define FC_REPORT_CURRENT(ER, ... ) (ER).pop_frame().push_frame( __FILE__, __LINE__, __func__, __VA_ARGS__ )

View file

@ -3,6 +3,7 @@
#include <fc/sstream.hpp> #include <fc/sstream.hpp>
#include <fc/value.hpp> #include <fc/value.hpp>
#include <fc/json.hpp> #include <fc/json.hpp>
#include <boost/exception_ptr.hpp>
namespace fc { namespace fc {
error_frame::error_frame( const fc::string& f, uint64_t l, const fc::string& m, const fc::string& d, fc::value met ) 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(); return ss.str();
} }
fc::exception_ptr error_report::copy_exception() {
return boost::copy_exception(*this);
}
} // namespace fc } // namespace fc

View file

@ -106,11 +106,9 @@ namespace fc { namespace json {
} else { } else {
auto e_itr = v.find( "error" ); auto e_itr = v.find( "error" );
if( e_itr != end ) { if( e_itr != end ) {
cur->set_exception( cur->set_exception( fc::value_cast<error_report>(e_itr->val["data"]).copy_exception() );
fc::copy_exception( } else {
fc::generic_exception( elog( "no result nor error field" );
value_cast<fc::string>(
e_itr->val["message"] ) ) ) );
} }
} }
} catch( ... ) { } catch( ... ) {