Branch data Line data Source code
1 : : // Copyright (c) 2022 The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #include <util/check.h>
6 : :
7 : : #include <bitcoin-build-config.h> // IWYU pragma: keep
8 : :
9 : : #include <clientversion.h>
10 : : #include <tinyformat.h>
11 : :
12 : : #include <cstdio>
13 : : #include <cstdlib>
14 : : #include <string>
15 : : #include <string_view>
16 : :
17 : 10 : std::string StrFormatInternalBug(std::string_view msg, std::string_view file, int line, std::string_view func)
18 : : {
19 : 10 : return strprintf("Internal bug detected: %s\n%s:%d (%s)\n"
20 : : "%s %s\n"
21 : : "Please report this issue here: %s\n",
22 [ + - ]: 20 : msg, file, line, func, CLIENT_NAME, FormatFullVersion(), CLIENT_BUGREPORT);
23 : : }
24 : :
25 : 10 : NonFatalCheckError::NonFatalCheckError(std::string_view msg, std::string_view file, int line, std::string_view func)
26 [ + - ]: 10 : : std::runtime_error{StrFormatInternalBug(msg, file, line, func)}
27 : : {
28 : 10 : }
29 : :
30 : : bool g_detail_test_only_CheckFailuresAreExceptionsNotAborts{false};
31 : :
32 : 1 : void assertion_fail(std::string_view file, int line, std::string_view func, std::string_view assertion)
33 : : {
34 [ + - ]: 1 : if (g_detail_test_only_CheckFailuresAreExceptionsNotAborts) {
35 [ + - ]: 1 : throw NonFatalCheckError{assertion, file, line, func};
36 : : }
37 : 0 : auto str = strprintf("%s:%s %s: Assertion `%s' failed.\n", file, line, func, assertion);
38 [ # # # # ]: 0 : fwrite(str.data(), 1, str.size(), stderr);
39 : 0 : std::abort();
40 : 0 : }
41 : :
42 : : std::atomic<bool> g_enable_dynamic_fuzz_determinism{false};
|