Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
util
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
18
std::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(),
24
CLIENT_NAME,
FormatFullVersion
(), CLIENT_BUGREPORT);
25
}
26
27
NonFatalCheckError::NonFatalCheckError
(std::string_view msg,
const
std::source_location& loc)
28
:
std
::runtime_error{
StrFormatInternalBug
(msg, loc)}
29
{
30
}
31
32
bool
g_detail_test_only_CheckFailuresAreExceptionsNotAborts
{
false
};
33
34
void
assertion_fail
(
const
std::source_location& loc, std::string_view assertion)
35
{
36
if
(
g_detail_test_only_CheckFailuresAreExceptionsNotAborts
) {
37
throw
NonFatalCheckError
{assertion, loc};
38
}
39
auto
str =
strprintf
(
"%s:%s %s: Assertion `%s' failed.\n"
, loc.file_name(), loc.line(), loc.function_name(), assertion);
40
fwrite(str.data(), 1, str.size(), stderr);
41
std::abort();
42
}
43
44
std::atomic<bool>
g_enable_dynamic_fuzz_determinism
{
false
};
g_detail_test_only_CheckFailuresAreExceptionsNotAborts
bool g_detail_test_only_CheckFailuresAreExceptionsNotAborts
Definition
check.cpp:32
g_enable_dynamic_fuzz_determinism
std::atomic< bool > g_enable_dynamic_fuzz_determinism
Definition
check.cpp:44
StrFormatInternalBug
std::string StrFormatInternalBug(std::string_view msg, const std::source_location &loc)
Definition
check.cpp:18
assertion_fail
void assertion_fail(const std::source_location &loc, std::string_view assertion)
Internal helper.
Definition
check.cpp:34
check.h
StrFormatInternalBug
std::string StrFormatInternalBug(std::string_view msg, const std::source_location &loc)
Definition
check.cpp:18
NonFatalCheckError
Definition
check.h:59
NonFatalCheckError::NonFatalCheckError
NonFatalCheckError(std::string_view msg, const std::source_location &loc)
Definition
check.cpp:27
FormatFullVersion
std::string FormatFullVersion()
Definition
clientversion.cpp:58
clientversion.h
std
Definition
common.h:29
tinyformat.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition
tinyformat.h:1172
Generated on
for Bitcoin Core by
1.17.0