Skip to content

Commit 6863ad7

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25112: util: Move error message formatting of NonFatalCheckError to cpp
2222ec7 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-ACK 2222ec7, only rebased and suggested changes since my recent [review](bitcoin/bitcoin#25112 (review)). aureleoules: ACK 2222ec7 Tree-SHA512: 313b3c891bb000cf606df1793b068f93df99915a254fbd67a45f003d440cce7355cdcc6b196f35757cc02d3697970d30e9de0d675f2aa8eb74107c13d663927a
2 parents f0c646f + 2222ec7 commit 6863ad7

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

ci/test/06_script_b.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ if [ "${RUN_TIDY}" = "true" ]; then
5959
" src/threadinterrupt.cpp"\
6060
" src/util/bip32.cpp"\
6161
" src/util/bytevectorhash.cpp"\
62+
" src/util/check.cpp"\
6263
" src/util/error.cpp"\
6364
" src/util/getuniquepath.cpp"\
6465
" src/util/hasher.cpp"\

src/util/check.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,23 @@
44

55
#include <util/check.h>
66

7+
#if defined(HAVE_CONFIG_H)
8+
#include <config/bitcoin-config.h>
9+
#endif
10+
711
#include <tinyformat.h>
812

13+
#include <cstdio>
14+
#include <cstdlib>
15+
#include <string>
16+
17+
18+
NonFatalCheckError::NonFatalCheckError(const char* msg, const char* file, int line, const char* func)
19+
: std::runtime_error{
20+
strprintf("Internal bug detected: \"%s\"\n%s:%d (%s)\nPlease report this issue here: %s\n", msg, file, line, func, PACKAGE_BUGREPORT)}
21+
{
22+
}
23+
924
void assertion_fail(const char* file, int line, const char* func, const char* assertion)
1025
{
1126
auto str = strprintf("%s:%s %s: Assertion `%s' failed.\n", file, line, func, assertion);

src/util/check.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,23 @@
55
#ifndef BITCOIN_UTIL_CHECK_H
66
#define BITCOIN_UTIL_CHECK_H
77

8-
#if defined(HAVE_CONFIG_H)
9-
#include <config/bitcoin-config.h>
10-
#endif
11-
128
#include <attributes.h>
13-
#include <tinyformat.h>
149

1510
#include <stdexcept>
11+
#include <utility>
1612

1713
class NonFatalCheckError : public std::runtime_error
1814
{
19-
using std::runtime_error::runtime_error;
15+
public:
16+
NonFatalCheckError(const char* msg, const char* file, int line, const char* func);
2017
};
2118

22-
#define format_internal_error(msg, file, line, func, report) \
23-
strprintf("Internal bug detected: \"%s\"\n%s:%d (%s)\nPlease report this issue here: %s\n", \
24-
msg, file, line, func, report)
25-
2619
/** Helper for CHECK_NONFATAL() */
2720
template <typename T>
2821
T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, const char* func, const char* assertion)
2922
{
30-
if (!(val)) {
31-
throw NonFatalCheckError(
32-
format_internal_error(assertion, file, line, func, PACKAGE_BUGREPORT));
23+
if (!val) {
24+
throw NonFatalCheckError{assertion, file, line, func};
3325
}
3426
return std::forward<T>(val);
3527
}
@@ -88,11 +80,9 @@ T&& inline_assertion_check(LIFETIMEBOUND T&& val, [[maybe_unused]] const char* f
8880

8981
/**
9082
* NONFATAL_UNREACHABLE() is a macro that is used to mark unreachable code. It throws a NonFatalCheckError.
91-
* This is used to mark code that is not yet implemented or is not yet reachable.
9283
*/
9384
#define NONFATAL_UNREACHABLE() \
9485
throw NonFatalCheckError( \
95-
format_internal_error("Unreachable code reached (non-fatal)", \
96-
__FILE__, __LINE__, __func__, PACKAGE_BUGREPORT))
86+
"Unreachable code reached (non-fatal)", __FILE__, __LINE__, __func__)
9787

9888
#endif // BITCOIN_UTIL_CHECK_H

0 commit comments

Comments
 (0)