diff --git a/include/fc/error_report.hpp b/include/fc/error_report.hpp index 9d59e4e..cd91a61 100644 --- a/include/fc/error_report.hpp +++ b/include/fc/error_report.hpp @@ -19,6 +19,9 @@ namespace fc { error_frame& operator=(const error_frame& ); error_frame& operator=(error_frame&& ); + fc::string to_string()const; + fc::string to_detail_string()const; + fc::string desc; fc::string file; int64_t line; @@ -43,6 +46,8 @@ namespace fc { error_report& push_frame( const fc::string& file, uint64_t line, const fc::string& method, const fc::string& desc, fc::value meta = fc::value() ); error_report& append( const error_report& e ); + fc::string to_string()const; + fc::string to_detail_string()const; error_context stack; ///< Human readable stack of what we were atempting to do. }; diff --git a/include/fc/string.hpp b/include/fc/string.hpp index 04a613b..370bb40 100644 --- a/include/fc/string.hpp +++ b/include/fc/string.hpp @@ -82,7 +82,7 @@ namespace fc { friend string operator + ( const string&, const string& ); friend string operator + ( const string&, char c ); - fc::string substr( int32_t start, int32_t len = 0x7fffffff ); + fc::string substr( int32_t start, int32_t len = 0x7fffffff )const; private: fc::fwd my; diff --git a/src/error_report.cpp b/src/error_report.cpp index 44a78c7..7df1b09 100644 --- a/src/error_report.cpp +++ b/src/error_report.cpp @@ -1,5 +1,8 @@ #include #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 ) @@ -70,4 +73,69 @@ fc::error_report& error_report::append( const error_report& e ) return *this; } +fc::string error_frame::to_detail_string()const { + fc::stringstream ss; + ss << to_string() << "\n\t"; + ss << file << ":" << line << "\t"<find( key.c_str() ); + if( itr != meta->end() ) { + ss << fc::json::to_string( itr->val ); + } else { + ss << "???"; + } + } + prev = next + 1; + // find the next $ + next = desc.find( '$', prev ); + } else { + // we didn't find it.. continue to while... + } + } else { + ss << desc[prev]; + ++prev; + next = desc.find( '$', prev ); + } + } + return ss.str(); +} +fc::string error_report::to_string()const { + fc::stringstream ss; + for( int i = 0; i < stack.size(); ++i ) { + ss << stack[i].to_string() << "\n"; + } + return ss.str(); +} +fc::string error_report::to_detail_string()const { + fc::stringstream ss; + for( int i = 0; i < stack.size(); ++i ) { + ss << stack[i].to_detail_string() << "\n"; + } + return ss.str(); +} + } // namespace fc diff --git a/src/json.cpp b/src/json.cpp index 895d743..9eeafeb 100644 --- a/src/json.cpp +++ b/src/json.cpp @@ -919,12 +919,11 @@ fc::string pretty_print( fc::vector&& v, uint8_t indent ) { value from_file( const fc::path& local_path ) { if( !exists(local_path) ) { - slog("..."); - FC_THROW_REPORT( "Source file '${filename}' does not exist", value().set("filename",local_path.string()) ); + FC_THROW_REPORT( "Source file ${filename} does not exist", value().set("filename",local_path.string()) ); } if( is_directory( local_path ) ) { - wlog("..."); - FC_THROW_MSG( "Source path '%s' is a directory, expected a file.", local_path.string() ); + FC_THROW_REPORT( "Source path ${path} is a directory; a file was expected", + value().set("path",local_path.string()) ); } // memory map the file diff --git a/src/string.cpp b/src/string.cpp index 5839e69..203e2c2 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -36,7 +36,7 @@ namespace fc { void string::clear() { my->clear(); } void string::resize( uint64_t s ) { my->resize(s); } - fc::string string::substr( int32_t start, int32_t len ) { return my->substr(start,len); } + fc::string string::substr( int32_t start, int32_t len )const { return my->substr(start,len); } const char* string::c_str()const { return my->c_str(); } bool string::operator == ( const char* s )const { return *my == s; }