exception.hpp: Allow enable/disable assert trip notifications with only one dirty file

This commit is contained in:
theoreticalbts 2015-07-06 14:50:59 -04:00
parent 46d85a3462
commit 787e4abf3f
2 changed files with 32 additions and 2 deletions

View file

@ -7,7 +7,6 @@
#include <fc/optional.hpp>
#include <exception>
#include <functional>
#include <iostream>
#include <unordered_map>
namespace fc
@ -292,6 +291,14 @@ namespace fc
FC_DECLARE_EXCEPTION( underflow_exception, underflow_code, "Integer Underflow" );
std::string except_str();
void record_assert_trip(
const char* filename,
uint32_t lineno,
const char* expr
);
extern bool enable_record_assert_trip;
} // namespace fc
#if __APPLE__
@ -314,7 +321,8 @@ namespace fc
FC_MULTILINE_MACRO_BEGIN \
if( UNLIKELY(!(TEST)) ) \
{ \
std::cout << "assert_trip: " << __FILE__ << ':' << __LINE__ << ": " << #TEST << "\n"; \
if( fc::enable_record_assert_trip ) \
fc::record_assert_trip( __FILE__, __LINE__, #TEST ); \
FC_THROW_EXCEPTION( fc::assert_exception, #TEST ": " __VA_ARGS__ ); \
} \
FC_MULTILINE_MACRO_END \

View file

@ -4,6 +4,8 @@
#include <fc/log/logger.hpp>
#include <fc/io/json.hpp>
#include <iostream>
namespace fc
{
FC_REGISTER_EXCEPTIONS( (timeout_exception)
@ -228,4 +230,24 @@ namespace fc
return *this;
}
void record_assert_trip(
const char* filename,
uint32_t lineno,
const char* expr
)
{
fc::mutable_variant_object assert_trip_info =
fc::mutable_variant_object()
("source_file", filename)
("source_lineno", lineno)
("expr", expr)
;
std::cout
<< "FC_ASSERT triggered: "
<< fc::json::to_string( assert_trip_info ) << "\n";
return;
}
bool enable_record_assert_trip = false;
} // fc