2022-03-26 12:41:28 +10:00
|
|
|
// Copyright (c) 2022 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <util/check.h>
|
|
|
|
|
2022-05-10 18:12:23 +02:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config/bitcoin-config.h>
|
|
|
|
#endif
|
|
|
|
|
2022-12-06 11:20:10 +01:00
|
|
|
#include <clientversion.h>
|
2022-03-26 12:41:28 +10:00
|
|
|
#include <tinyformat.h>
|
|
|
|
|
2022-05-10 18:12:23 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
2023-01-24 12:07:03 +01:00
|
|
|
#include <string_view>
|
2022-05-10 18:12:23 +02:00
|
|
|
|
2023-01-24 12:07:03 +01:00
|
|
|
std::string StrFormatInternalBug(std::string_view msg, std::string_view file, int line, std::string_view func)
|
2022-12-01 12:20:45 -05:00
|
|
|
{
|
2023-08-18 02:34:10 +00:00
|
|
|
return strprintf("Internal bug detected: %s\n%s:%d (%s)\n"
|
2022-12-06 11:20:10 +01:00
|
|
|
"%s %s\n"
|
|
|
|
"Please report this issue here: %s\n",
|
|
|
|
msg, file, line, func, PACKAGE_NAME, FormatFullVersion(), PACKAGE_BUGREPORT);
|
2022-12-01 12:20:45 -05:00
|
|
|
}
|
2022-05-10 18:12:23 +02:00
|
|
|
|
2023-01-24 12:07:03 +01:00
|
|
|
NonFatalCheckError::NonFatalCheckError(std::string_view msg, std::string_view file, int line, std::string_view func)
|
2022-12-01 12:20:45 -05:00
|
|
|
: std::runtime_error{StrFormatInternalBug(msg, file, line, func)}
|
2022-05-10 18:12:23 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-24 12:07:03 +01:00
|
|
|
void assertion_fail(std::string_view file, int line, std::string_view func, std::string_view assertion)
|
2022-03-26 12:41:28 +10:00
|
|
|
{
|
|
|
|
auto str = strprintf("%s:%s %s: Assertion `%s' failed.\n", file, line, func, assertion);
|
|
|
|
fwrite(str.data(), 1, str.size(), stderr);
|
|
|
|
std::abort();
|
|
|
|
}
|