Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
check.cpp
Go to the documentation of this file.
1// Copyright (c) 2022-present 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 <source_location>
15#include <string>
16#include <string_view>
17
18std::string StrFormatInternalBug(std::string_view msg, const std::source_location& loc)
19{
20 return strprintf("Internal bug detected: %s\n%s:%d (%s)\n"
21 "%s %s\n"
22 "Please report this issue here: %s\n",
23 msg, loc.file_name(), loc.line(), loc.function_name(),
25}
26
27std::string StrFormatFailedCheck(std::string_view assertion)
28{
29 return strprintf("`%s` check failed", assertion);
30}
31
32NonFatalCheckError::NonFatalCheckError(std::string_view msg, const std::source_location& loc)
33 : std::runtime_error{StrFormatInternalBug(msg, loc)}
34{
35}
36
38
39void internal_abort_helper(const std::source_location& loc, std::string_view error_msg)
40{
43 }
44 auto str = strprintf("%s:%s %s: %s.\n", loc.file_name(), loc.line(), loc.function_name(), error_msg);
45 fwrite(str.data(), 1, str.size(), stderr);
46 std::abort();
47}
48
49void internal_non_fatal_helper(const std::source_location& loc, std::string_view error_msg)
50{
51 if constexpr (G_ABORT_ON_FAILED_ASSUME) {
53 }
55}
56
57std::atomic<bool> g_enable_dynamic_fuzz_determinism{false};
std::string StrFormatFailedCheck(std::string_view assertion)
Definition check.cpp:27
void internal_abort_helper(const std::source_location &loc, std::string_view error_msg)
Internal helper. The noreturn enables optimizers to discard invalid paths.
Definition check.cpp:39
bool g_detail_test_only_CheckFailuresAreExceptionsNotAborts
Definition check.cpp:37
void internal_non_fatal_helper(const std::source_location &loc, std::string_view error_msg)
Internal helper. The noreturn enables optimizers to discard invalid paths.
Definition check.cpp:49
std::atomic< bool > g_enable_dynamic_fuzz_determinism
Definition check.cpp:57
std::string StrFormatInternalBug(std::string_view msg, const std::source_location &loc)
Definition check.cpp:18
constexpr bool G_ABORT_ON_FAILED_ASSUME
Definition check.h:28
NonFatalCheckError(std::string_view msg, const std::source_location &loc)
Definition check.cpp:32
std::string FormatFullVersion()
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82