exception.hpp: Allow enable/disable assert trip notifications with only one dirty file
This commit is contained in:
parent
46d85a3462
commit
787e4abf3f
2 changed files with 32 additions and 2 deletions
|
|
@ -7,7 +7,6 @@
|
||||||
#include <fc/optional.hpp>
|
#include <fc/optional.hpp>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace fc
|
namespace fc
|
||||||
|
|
@ -292,6 +291,14 @@ namespace fc
|
||||||
FC_DECLARE_EXCEPTION( underflow_exception, underflow_code, "Integer Underflow" );
|
FC_DECLARE_EXCEPTION( underflow_exception, underflow_code, "Integer Underflow" );
|
||||||
|
|
||||||
std::string except_str();
|
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
|
} // namespace fc
|
||||||
|
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
|
|
@ -314,7 +321,8 @@ namespace fc
|
||||||
FC_MULTILINE_MACRO_BEGIN \
|
FC_MULTILINE_MACRO_BEGIN \
|
||||||
if( UNLIKELY(!(TEST)) ) \
|
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_THROW_EXCEPTION( fc::assert_exception, #TEST ": " __VA_ARGS__ ); \
|
||||||
} \
|
} \
|
||||||
FC_MULTILINE_MACRO_END \
|
FC_MULTILINE_MACRO_END \
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
#include <fc/log/logger.hpp>
|
#include <fc/log/logger.hpp>
|
||||||
#include <fc/io/json.hpp>
|
#include <fc/io/json.hpp>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace fc
|
namespace fc
|
||||||
{
|
{
|
||||||
FC_REGISTER_EXCEPTIONS( (timeout_exception)
|
FC_REGISTER_EXCEPTIONS( (timeout_exception)
|
||||||
|
|
@ -228,4 +230,24 @@ namespace fc
|
||||||
return *this;
|
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
|
} // fc
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue