aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorMacroFake <falke.marco@gmail.com>2022-05-10 18:12:23 +0200
committerMacroFake <falke.marco@gmail.com>2022-11-16 12:21:33 +0100
commit2222ec71fdf573a15bb593fc0dd42d2d28ca5449 (patch)
treee7ed74c13c1f72e173cdfa84dacf42b67efeaea8 /src/util
parent547a96362888d2fa02d496c192dcdb7ea7d72813 (diff)
downloadbitcoin-2222ec71fdf573a15bb593fc0dd42d2d28ca5449.tar.xz
util: Move error message formatting of NonFatalCheckError to cpp
This allows to strip down the header file
Diffstat (limited to 'src/util')
-rw-r--r--src/util/check.cpp15
-rw-r--r--src/util/check.h22
2 files changed, 21 insertions, 16 deletions
diff --git a/src/util/check.cpp b/src/util/check.cpp
index 2a9f885560..e50d6087d0 100644
--- a/src/util/check.cpp
+++ b/src/util/check.cpp
@@ -4,8 +4,23 @@
#include <util/check.h>
+#if defined(HAVE_CONFIG_H)
+#include <config/bitcoin-config.h>
+#endif
+
#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)
{
auto str = strprintf("%s:%s %s: Assertion `%s' failed.\n", file, line, func, assertion);
diff --git a/src/util/check.h b/src/util/check.h
index 49f07de9dd..b6c03bed2a 100644
--- a/src/util/check.h
+++ b/src/util/check.h
@@ -5,31 +5,23 @@
#ifndef BITCOIN_UTIL_CHECK_H
#define BITCOIN_UTIL_CHECK_H
-#if defined(HAVE_CONFIG_H)
-#include <config/bitcoin-config.h>
-#endif
-
#include <attributes.h>
-#include <tinyformat.h>
#include <stdexcept>
+#include <utility>
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() */
template <typename T>
T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, const char* func, const char* assertion)
{
- if (!(val)) {
- throw NonFatalCheckError(
- format_internal_error(assertion, file, line, func, PACKAGE_BUGREPORT));
+ if (!val) {
+ throw NonFatalCheckError{assertion, file, line, func};
}
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.
- * This is used to mark code that is not yet implemented or is not yet reachable.
*/
#define NONFATAL_UNREACHABLE() \
throw NonFatalCheckError( \
- format_internal_error("Unreachable code reached (non-fatal)", \
- __FILE__, __LINE__, __func__, PACKAGE_BUGREPORT))
+ "Unreachable code reached (non-fatal)", __FILE__, __LINE__, __func__)
#endif // BITCOIN_UTIL_CHECK_H