mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 23:42:33 +02:00
Merge bitcoin/bitcoin#25112: util: Move error message formatting of NonFatalCheckError to cpp
2222ec71fd
util: Move error message formatting of NonFatalCheckError to cpp (MacroFake) Pull request description: This allows to strip down the header file. ACKs for top commit: hebasto: re-ACK2222ec71fd
, only rebased and suggested changes since my recent [review](https://github.com/bitcoin/bitcoin/pull/25112#pullrequestreview-1182361605). aureleoules: ACK2222ec71fd
Tree-SHA512: 313b3c891bb000cf606df1793b068f93df99915a254fbd67a45f003d440cce7355cdcc6b196f35757cc02d3697970d30e9de0d675f2aa8eb74107c13d663927a
This commit is contained in:
commit
6863ad79a6
@ -59,6 +59,7 @@ if [ "${RUN_TIDY}" = "true" ]; then
|
|||||||
" src/threadinterrupt.cpp"\
|
" src/threadinterrupt.cpp"\
|
||||||
" src/util/bip32.cpp"\
|
" src/util/bip32.cpp"\
|
||||||
" src/util/bytevectorhash.cpp"\
|
" src/util/bytevectorhash.cpp"\
|
||||||
|
" src/util/check.cpp"\
|
||||||
" src/util/error.cpp"\
|
" src/util/error.cpp"\
|
||||||
" src/util/getuniquepath.cpp"\
|
" src/util/getuniquepath.cpp"\
|
||||||
" src/util/hasher.cpp"\
|
" src/util/hasher.cpp"\
|
||||||
|
@ -4,8 +4,23 @@
|
|||||||
|
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
|
|
||||||
|
#if defined(HAVE_CONFIG_H)
|
||||||
|
#include <config/bitcoin-config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
NonFatalCheckError::NonFatalCheckError(const char* msg, const char* file, int line, const char* func)
|
||||||
|
: std::runtime_error{
|
||||||
|
strprintf("Internal bug detected: \"%s\"\n%s:%d (%s)\nPlease report this issue here: %s\n", msg, file, line, func, PACKAGE_BUGREPORT)}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void assertion_fail(const char* file, int line, const char* func, const char* assertion)
|
void assertion_fail(const char* file, int line, const char* func, const char* assertion)
|
||||||
{
|
{
|
||||||
auto str = strprintf("%s:%s %s: Assertion `%s' failed.\n", file, line, func, assertion);
|
auto str = strprintf("%s:%s %s: Assertion `%s' failed.\n", file, line, func, assertion);
|
||||||
|
@ -5,31 +5,23 @@
|
|||||||
#ifndef BITCOIN_UTIL_CHECK_H
|
#ifndef BITCOIN_UTIL_CHECK_H
|
||||||
#define BITCOIN_UTIL_CHECK_H
|
#define BITCOIN_UTIL_CHECK_H
|
||||||
|
|
||||||
#if defined(HAVE_CONFIG_H)
|
|
||||||
#include <config/bitcoin-config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <attributes.h>
|
#include <attributes.h>
|
||||||
#include <tinyformat.h>
|
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
class NonFatalCheckError : public std::runtime_error
|
class NonFatalCheckError : public std::runtime_error
|
||||||
{
|
{
|
||||||
using std::runtime_error::runtime_error;
|
public:
|
||||||
|
NonFatalCheckError(const char* msg, const char* file, int line, const char* func);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define format_internal_error(msg, file, line, func, report) \
|
|
||||||
strprintf("Internal bug detected: \"%s\"\n%s:%d (%s)\nPlease report this issue here: %s\n", \
|
|
||||||
msg, file, line, func, report)
|
|
||||||
|
|
||||||
/** Helper for CHECK_NONFATAL() */
|
/** Helper for CHECK_NONFATAL() */
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, const char* func, const char* assertion)
|
T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, const char* func, const char* assertion)
|
||||||
{
|
{
|
||||||
if (!(val)) {
|
if (!val) {
|
||||||
throw NonFatalCheckError(
|
throw NonFatalCheckError{assertion, file, line, func};
|
||||||
format_internal_error(assertion, file, line, func, PACKAGE_BUGREPORT));
|
|
||||||
}
|
}
|
||||||
return std::forward<T>(val);
|
return std::forward<T>(val);
|
||||||
}
|
}
|
||||||
@ -88,11 +80,9 @@ T&& inline_assertion_check(LIFETIMEBOUND T&& val, [[maybe_unused]] const char* f
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* NONFATAL_UNREACHABLE() is a macro that is used to mark unreachable code. It throws a NonFatalCheckError.
|
* NONFATAL_UNREACHABLE() is a macro that is used to mark unreachable code. It throws a NonFatalCheckError.
|
||||||
* This is used to mark code that is not yet implemented or is not yet reachable.
|
|
||||||
*/
|
*/
|
||||||
#define NONFATAL_UNREACHABLE() \
|
#define NONFATAL_UNREACHABLE() \
|
||||||
throw NonFatalCheckError( \
|
throw NonFatalCheckError( \
|
||||||
format_internal_error("Unreachable code reached (non-fatal)", \
|
"Unreachable code reached (non-fatal)", __FILE__, __LINE__, __func__)
|
||||||
__FILE__, __LINE__, __func__, PACKAGE_BUGREPORT))
|
|
||||||
|
|
||||||
#endif // BITCOIN_UTIL_CHECK_H
|
#endif // BITCOIN_UTIL_CHECK_H
|
||||||
|
Loading…
Reference in New Issue
Block a user