util: Add StrFormatInternalBug and STR_INTERNAL_BUG

This commit is contained in:
MarcoFalke 2022-12-01 12:20:45 -05:00 committed by Andrew Chow
parent bcee94d107
commit c6e7f224c1
2 changed files with 9 additions and 2 deletions

View file

@ -14,10 +14,13 @@
#include <cstdlib>
#include <string>
std::string StrFormatInternalBug(const char* msg, const char* file, int line, const char* func)
{
return strprintf("Internal bug detected: \"%s\"\n%s:%d (%s)\nPlease report this issue here: %s\n", msg, file, line, func, PACKAGE_BUGREPORT);
}
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)}
: std::runtime_error{StrFormatInternalBug(msg, file, line, func)}
{
}

View file

@ -10,12 +10,16 @@
#include <stdexcept>
#include <utility>
std::string StrFormatInternalBug(const char* msg, const char* file, int line, const char* func);
class NonFatalCheckError : public std::runtime_error
{
public:
NonFatalCheckError(const char* msg, const char* file, int line, const char* func);
};
#define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), __FILE__, __LINE__, __func__)
/** 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)