mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
feat(Core/Common): add support fmt style for ASSERT and ABORT (#10355)
* feat(Core/Common): add support fmt style for ASSERT and ABORT * correct CheckCompactArrayMaskOverflow * 1 * Update src/server/game/Spells/Spell.cpp
This commit is contained in:
232
apps/Fmt/FormatReplace.py
Normal file
232
apps/Fmt/FormatReplace.py
Normal file
@@ -0,0 +1,232 @@
|
||||
import pathlib
|
||||
from os import getcwd
|
||||
|
||||
if not getcwd().endswith('src') and not getcwd().endswith('modules'):
|
||||
print('Run this from the src or modules directory!')
|
||||
print('(Invoke as \'python ../apps/Fmt/FormatReplace.py\')')
|
||||
exit(1)
|
||||
|
||||
def isASSERT(line):
|
||||
substring = 'ASSERT'
|
||||
if substring in line:
|
||||
return True
|
||||
else :
|
||||
return False
|
||||
|
||||
def isABORTMSG(line):
|
||||
substring = 'ABORT_MSG'
|
||||
if substring in line:
|
||||
return True
|
||||
else :
|
||||
return False
|
||||
|
||||
# def islog(line):
|
||||
# substring = 'LOG_'
|
||||
# if substring in line:
|
||||
# return True
|
||||
# else :
|
||||
# return False
|
||||
|
||||
# def isSendSysMessage(line):
|
||||
# substring = 'SendSysMessage'
|
||||
# if substring in line:
|
||||
# return True
|
||||
# else :
|
||||
# return False
|
||||
|
||||
# def isPSendSysMessage(line):
|
||||
# substring = 'PSendSysMessage'
|
||||
# if substring in line:
|
||||
# return True
|
||||
# else :
|
||||
# return False
|
||||
|
||||
# def isPQuery(line):
|
||||
# substring = 'PQuery'
|
||||
# if substring in line:
|
||||
# return True
|
||||
# else :
|
||||
# return False
|
||||
|
||||
# def isPExecute(line):
|
||||
# substring = 'PExecute'
|
||||
# if substring in line:
|
||||
# return True
|
||||
# else :
|
||||
# return False
|
||||
|
||||
# def isPAppend(line):
|
||||
# substring = 'PAppend'
|
||||
# if substring in line:
|
||||
# return True
|
||||
# else :
|
||||
# return False
|
||||
|
||||
# def isStringFormat(line):
|
||||
# substring = 'StringFormat'
|
||||
# if substring in line:
|
||||
# return True
|
||||
# else :
|
||||
# return False
|
||||
|
||||
def haveDelimeter(line):
|
||||
if ';' in line:
|
||||
return True
|
||||
else :
|
||||
return False
|
||||
|
||||
def checkSoloLine(line):
|
||||
if isABORTMSG(line):
|
||||
line = line.replace("ABORT_MSG", "ABORT");
|
||||
return handleCleanup(line), False
|
||||
elif isASSERT(line):
|
||||
return handleCleanup(line), False
|
||||
# elif islog(line):
|
||||
# return handleCleanup(line), False
|
||||
# elif isPExecute(line):
|
||||
# return handleCleanup(line), False
|
||||
# elif isPQuery(line):
|
||||
# return handleCleanup(line), False
|
||||
# elif isPAppend(line):
|
||||
# return handleCleanup(line), False
|
||||
# elif isSendSysMessage(line):
|
||||
# return handleCleanup(line), False
|
||||
# elif isPSendSysMessage(line):
|
||||
# return handleCleanup(line), False
|
||||
# elif isStringFormat(line):
|
||||
# return handleCleanup(line), False
|
||||
else:
|
||||
return line, False
|
||||
|
||||
def startMultiLine(line):
|
||||
if isABORTMSG(line):
|
||||
line = line.replace("ABORT_MSG", "ABORT");
|
||||
return handleCleanup(line), True
|
||||
elif isASSERT(line):
|
||||
return handleCleanup(line), True
|
||||
# elif islog(line):
|
||||
# return handleCleanup(line), True
|
||||
# elif isSendSysMessage(line):
|
||||
# return handleCleanup(line), True
|
||||
# elif isPSendSysMessage(line):
|
||||
# return handleCleanup(line), True
|
||||
# elif isPQuery(line):
|
||||
# return handleCleanup(line), True
|
||||
# elif isPExecute(line):
|
||||
# return handleCleanup(line), True
|
||||
# elif isPAppend(line):
|
||||
# return handleCleanup(line), True
|
||||
# elif isStringFormat(line):
|
||||
# return handleCleanup(line), True
|
||||
else :
|
||||
return line, False
|
||||
|
||||
def continueMultiLine(line, existPrevLine):
|
||||
if haveDelimeter(line):
|
||||
existPrevLine = False;
|
||||
return handleCleanup(line), existPrevLine
|
||||
|
||||
def checkTextLine(line, existPrevLine):
|
||||
if existPrevLine:
|
||||
return continueMultiLine(line, existPrevLine)
|
||||
else :
|
||||
if haveDelimeter(line):
|
||||
return checkSoloLine(line)
|
||||
else :
|
||||
return startMultiLine(line)
|
||||
|
||||
def handleCleanup(line):
|
||||
line = line.replace("%s", "{}");
|
||||
line = line.replace("%u", "{}");
|
||||
line = line.replace("%hu", "{}");
|
||||
line = line.replace("%lu", "{}");
|
||||
line = line.replace("%llu", "{}");
|
||||
line = line.replace("%zu", "{}");
|
||||
line = line.replace("%02u", "{:02}");
|
||||
line = line.replace("%03u", "{:03}");
|
||||
line = line.replace("%04u", "{:04}");
|
||||
line = line.replace("%05u", "{:05}");
|
||||
line = line.replace("%02i", "{:02}");
|
||||
line = line.replace("%03i", "{:03}");
|
||||
line = line.replace("%04i", "{:04}");
|
||||
line = line.replace("%05i", "{:05}");
|
||||
line = line.replace("%02d", "{:02}");
|
||||
line = line.replace("%03d", "{:03}");
|
||||
line = line.replace("%04d", "{:04}");
|
||||
line = line.replace("%05d", "{:05}");
|
||||
line = line.replace("%d", "{}");
|
||||
line = line.replace("%i", "{}");
|
||||
line = line.replace("%x", "{:x}");
|
||||
line = line.replace("%X", "{:X}");
|
||||
line = line.replace("%lx", "{:x}");
|
||||
line = line.replace("%lX", "{:X}");
|
||||
line = line.replace("%02X", "{:02X}");
|
||||
line = line.replace("%08X", "{:08X}");
|
||||
line = line.replace("%f", "{}");
|
||||
line = line.replace("%.1f", "{0:.1f}");
|
||||
line = line.replace("%.2f", "{0:.2f}");
|
||||
line = line.replace("%.3f", "{0:.3f}");
|
||||
line = line.replace("%.4f", "{0:.4f}");
|
||||
line = line.replace("%.5f", "{0:.5f}");
|
||||
line = line.replace("%3.1f", "{:3.1f}");
|
||||
line = line.replace("%%", "%");
|
||||
line = line.replace(".c_str()", "");
|
||||
line = line.replace("\" SZFMTD \"", "{}");
|
||||
line = line.replace("\" UI64FMTD \"", "{}");
|
||||
# line = line.replace("\" STRING_VIEW_FMT \"", "{}");
|
||||
# line = line.replace("STRING_VIEW_FMT_ARG", "");
|
||||
return line
|
||||
|
||||
def getDefaultfile(name):
|
||||
file1 = open(name, "r+", encoding="utf8", errors='replace')
|
||||
|
||||
result = ''
|
||||
|
||||
while True:
|
||||
line = file1.readline()
|
||||
|
||||
if not line:
|
||||
break
|
||||
|
||||
result += line
|
||||
|
||||
file1.close
|
||||
return result
|
||||
|
||||
def getModifiedfile(name):
|
||||
file1 = open(name, "r+", encoding="utf8", errors='replace')
|
||||
|
||||
prevLines = False
|
||||
result = ''
|
||||
|
||||
while True:
|
||||
line = file1.readline()
|
||||
|
||||
if not line:
|
||||
break
|
||||
|
||||
line, prevLines = checkTextLine(line, prevLines)
|
||||
result += line
|
||||
|
||||
file1.close
|
||||
return result
|
||||
|
||||
def updModifiedfile(name, text):
|
||||
file = open(name, "w", encoding="utf8", errors='replace')
|
||||
file.write(text)
|
||||
file.close()
|
||||
|
||||
def handlefile(name):
|
||||
oldtext = getDefaultfile(name)
|
||||
newtext = getModifiedfile(name)
|
||||
|
||||
if oldtext != newtext:
|
||||
updModifiedfile(name, newtext)
|
||||
|
||||
p = pathlib.Path('.')
|
||||
for i in p.glob('**/*'):
|
||||
fname = i.absolute()
|
||||
if '.cpp' in i.name:
|
||||
handlefile(fname)
|
||||
if '.h' in i.name:
|
||||
handlefile(fname)
|
||||
@@ -81,7 +81,7 @@ namespace MMAP
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(false, "Invalid mapId %u passed to MMapMgr after startup in thread unsafe environment", mapId);
|
||||
ABORT("Invalid mapId {} passed to MMapMgr after startup in thread unsafe environment", mapId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace VMAP
|
||||
instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, nullptr)).first;
|
||||
}
|
||||
else
|
||||
ASSERT(false, "Invalid mapId %u tile [%u, %u] passed to VMapMgr2 after startup in thread unsafe environment",
|
||||
ABORT("Invalid mapId {} tile [{}, {}] passed to VMapMgr2 after startup in thread unsafe environment",
|
||||
mapId, tileX, tileY);
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace
|
||||
PrintError(fileName, "> Config::LoadFile: Found incorrect option '{}' in config file '{}'. Skip", optionName, fileName);
|
||||
|
||||
#ifdef CONFIG_ABORT_INCORRECT_OPTIONS
|
||||
ABORT_MSG("> Core can't start if found incorrect options");
|
||||
ABORT("> Core can't start if found incorrect options");
|
||||
#endif
|
||||
|
||||
return;
|
||||
|
||||
@@ -193,11 +193,11 @@ void BigNumber::GetBytes(uint8* buf, size_t bufsize, bool littleEndian) const
|
||||
{
|
||||
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
int nBytes = GetNumBytes();
|
||||
ASSERT(nBytes >= 0, "Bignum has negative number of bytes (%d).", nBytes);
|
||||
ASSERT(nBytes >= 0, "Bignum has negative number of bytes ({}).", nBytes);
|
||||
std::size_t numBytes = static_cast<std::size_t>(nBytes);
|
||||
|
||||
// too large to store
|
||||
ASSERT(numBytes <= bufsize, "Buffer of size %zu is too small to hold bignum with %zu bytes.\n", bufsize, numBytes);
|
||||
ASSERT(numBytes <= bufsize, "Buffer of size {} is too small to hold bignum with {} bytes.\n", bufsize, numBytes);
|
||||
|
||||
// If we need more bytes than length of BigNumber set the rest to 0
|
||||
if (numBytes < bufsize)
|
||||
@@ -214,7 +214,7 @@ void BigNumber::GetBytes(uint8* buf, size_t bufsize, bool littleEndian) const
|
||||
}
|
||||
#else
|
||||
int res = littleEndian ? BN_bn2lebinpad(_bn, buf, bufsize) : BN_bn2binpad(_bn, buf, bufsize);
|
||||
ASSERT(res > 0, "Buffer of size %zu is too small to hold bignum with %d bytes.\n", bufsize, BN_num_bytes(_bn));
|
||||
ASSERT(res > 0, "Buffer of size {} is too small to hold bignum with {} bytes.\n", bufsize, BN_num_bytes(_bn));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
* Copyright (C) 2008-2019 TrinityCore <https://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by the
|
||||
* Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Errors.h"
|
||||
#include "StringFormat.h"
|
||||
#include <cstdarg>
|
||||
#include "Duration.h"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <thread>
|
||||
@@ -29,117 +39,121 @@
|
||||
RaiseException(EXCEPTION_ASSERTION_FAILURE, 0, 2, execeptionArgs);
|
||||
#else
|
||||
// should be easily accessible in gdb
|
||||
extern "C" { char const* TrinityAssertionFailedMessage = nullptr; }
|
||||
extern "C" { char const* AcoreAssertionFailedMessage = nullptr; }
|
||||
#define Crash(message) \
|
||||
TrinityAssertionFailedMessage = strdup(message); \
|
||||
AcoreAssertionFailedMessage = strdup(message); \
|
||||
*((volatile int*)nullptr) = 0; \
|
||||
exit(1);
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string FormatAssertionMessage(char const* format, va_list args)
|
||||
/**
|
||||
* @name MakeMessage
|
||||
* @brief Make message for display erros
|
||||
* @param messageType Message type (ASSERTION FAILED, FATAL ERROR, ERROR) end etc
|
||||
* @param file Path to file
|
||||
* @param line Line number in file
|
||||
* @param function Functionn name
|
||||
* @param message Condition to string format
|
||||
* @param fmtMessage [optional] Display format message after condition
|
||||
* @param debugInfo [optional] Display debug info
|
||||
*/
|
||||
inline std::string MakeMessage(std::string_view messageType, std::string_view file, uint32 line, std::string_view function,
|
||||
std::string_view message, std::string_view fmtMessage = {}, std::string_view debugInfo = {})
|
||||
{
|
||||
std::string formatted;
|
||||
va_list len;
|
||||
std::string msg = Acore::StringFormatFmt("\n>> {}\n\n# Location '{}:{}'\n# Function '{}'\n# Condition '{}'\n", messageType, file, line, function, message);
|
||||
|
||||
va_copy(len, args);
|
||||
int32 length = vsnprintf(nullptr, 0, format, len);
|
||||
va_end(len);
|
||||
if (!fmtMessage.empty())
|
||||
{
|
||||
msg.append(Acore::StringFormatFmt("# Message '{}'\n", fmtMessage));
|
||||
}
|
||||
|
||||
formatted.resize(length);
|
||||
vsnprintf(&formatted[0], length + 1, format, args);
|
||||
if (!debugInfo.empty())
|
||||
{
|
||||
msg.append(Acore::StringFormatFmt("\n# Debug info: '{}'\n", debugInfo));
|
||||
}
|
||||
|
||||
return formatted;
|
||||
return Acore::StringFormatFmt(
|
||||
"#{0:-^{2}}#\n"
|
||||
" {1: ^{2}} \n"
|
||||
"#{0:-^{2}}#\n", "", msg, 70);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name MakeAbortMessage
|
||||
* @brief Make message for display erros
|
||||
* @param file Path to file
|
||||
* @param line Line number in file
|
||||
* @param function Functionn name
|
||||
* @param fmtMessage [optional] Display format message after condition
|
||||
*/
|
||||
inline std::string MakeAbortMessage(std::string_view file, uint32 line, std::string_view function, std::string_view fmtMessage = {})
|
||||
{
|
||||
std::string msg = Acore::StringFormatFmt("\n>> ABORTED\n\n# Location '{}:{}'\n# Function '{}'\n", file, line, function);
|
||||
|
||||
if (!fmtMessage.empty())
|
||||
{
|
||||
msg.append(Acore::StringFormatFmt("# Message '{}'\n", fmtMessage));
|
||||
}
|
||||
|
||||
return Acore::StringFormatFmt(
|
||||
"\n#{0:-^{2}}#\n"
|
||||
" {1: ^{2}} \n"
|
||||
"#{0:-^{2}}#\n", "", msg, 70);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Acore
|
||||
void Acore::Assert(std::string_view file, uint32 line, std::string_view function, std::string_view debugInfo, std::string_view message, std::string_view fmtMessage /*= {}*/)
|
||||
{
|
||||
void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message)
|
||||
{
|
||||
std::string formattedMessage = Acore::StringFormat("\n%s:%i in %s ASSERTION FAILED:\n %s\n", file, line, function, message) + debugInfo + '\n';
|
||||
fprintf(stderr, "%s", formattedMessage.c_str());
|
||||
std::string formattedMessage = MakeMessage("ASSERTION FAILED", file, line, function, message, fmtMessage, debugInfo);
|
||||
fmt::print(stderr, "{}", formattedMessage);
|
||||
fflush(stderr);
|
||||
Crash(formattedMessage.c_str());
|
||||
}
|
||||
|
||||
void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message, char const* format, ...)
|
||||
void Acore::Fatal(std::string_view file, uint32 line, std::string_view function, std::string_view message, std::string_view fmtMessage /*= {}*/)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
std::string formattedMessage = Acore::StringFormat("\n%s:%i in %s ASSERTION FAILED:\n %s\n", file, line, function, message) + FormatAssertionMessage(format, args) + '\n' + debugInfo + '\n';
|
||||
va_end(args);
|
||||
|
||||
fprintf(stderr, "%s", formattedMessage.c_str());
|
||||
std::string formattedMessage = MakeMessage("FATAL ERROR", file, line, function, message, fmtMessage);
|
||||
fmt::print(stderr, "{}", formattedMessage);
|
||||
fflush(stderr);
|
||||
|
||||
std::this_thread::sleep_for(10s);
|
||||
Crash(formattedMessage.c_str());
|
||||
}
|
||||
|
||||
void Fatal(char const* file, int line, char const* function, char const* message, ...)
|
||||
void Acore::Error(std::string_view file, uint32 line, std::string_view function, std::string_view message)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
|
||||
std::string formattedMessage = Acore::StringFormat("\n%s:%i in %s FATAL ERROR:\n", file, line, function) + FormatAssertionMessage(message, args) + '\n';
|
||||
va_end(args);
|
||||
|
||||
fprintf(stderr, "%s", formattedMessage.c_str());
|
||||
std::string formattedMessage = MakeMessage("ERROR", file, line, function, message);
|
||||
fmt::print(stderr, "{}", formattedMessage);
|
||||
fflush(stderr);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
std::this_thread::sleep_for(10s);
|
||||
Crash(formattedMessage.c_str());
|
||||
}
|
||||
|
||||
void Error(char const* file, int line, char const* function, char const* message)
|
||||
void Acore::Warning(std::string_view file, uint32 line, std::string_view function, std::string_view message)
|
||||
{
|
||||
std::string formattedMessage = Acore::StringFormat("\n%s:%i in %s ERROR:\n %s\n", file, line, function, message);
|
||||
fprintf(stderr, "%s", formattedMessage.c_str());
|
||||
std::string formattedMessage = MakeMessage("WARNING", file, line, function, message);
|
||||
fmt::print(stderr, "{}", formattedMessage);
|
||||
}
|
||||
|
||||
void Acore::Abort(std::string_view file, uint32 line, std::string_view function, std::string_view fmtMessage /*= {}*/)
|
||||
{
|
||||
std::string formattedMessage = MakeAbortMessage(file, line, function, fmtMessage);
|
||||
fmt::print(stderr, "{}", formattedMessage);
|
||||
fflush(stderr);
|
||||
std::this_thread::sleep_for(10s);
|
||||
Crash(formattedMessage.c_str());
|
||||
}
|
||||
|
||||
void Warning(char const* file, int line, char const* function, char const* message)
|
||||
{
|
||||
fprintf(stderr, "\n%s:%i in %s WARNING:\n %s\n",
|
||||
file, line, function, message);
|
||||
}
|
||||
|
||||
void Abort(char const* file, int line, char const* function)
|
||||
{
|
||||
std::string formattedMessage = Acore::StringFormat("\n%s:%i in %s ABORTED.\n", file, line, function);
|
||||
fprintf(stderr, "%s", formattedMessage.c_str());
|
||||
fflush(stderr);
|
||||
Crash(formattedMessage.c_str());
|
||||
}
|
||||
|
||||
void Abort(char const* file, int line, char const* function, char const* message, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
|
||||
std::string formattedMessage = StringFormat("\n%s:%i in %s ABORTED:\n", file, line, function) + FormatAssertionMessage(message, args) + '\n';
|
||||
va_end(args);
|
||||
|
||||
fprintf(stderr, "%s", formattedMessage.c_str());
|
||||
fflush(stderr);
|
||||
|
||||
Crash(formattedMessage.c_str());
|
||||
}
|
||||
|
||||
void AbortHandler(int sigval)
|
||||
void Acore::AbortHandler(int sigval)
|
||||
{
|
||||
// nothing useful to log here, no way to pass args
|
||||
std::string formattedMessage = Acore::StringFormat("Caught signal %i\n", sigval);
|
||||
fprintf(stderr, "%s", formattedMessage.c_str());
|
||||
std::string formattedMessage = StringFormatFmt("Caught signal {}\n", sigval);
|
||||
fmt::print(stderr, "{}", formattedMessage);
|
||||
fflush(stderr);
|
||||
Crash(formattedMessage.c_str());
|
||||
}
|
||||
|
||||
} // namespace Acore
|
||||
|
||||
std::string GetDebugInfo()
|
||||
{
|
||||
return "";
|
||||
|
||||
@@ -1,55 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
* Copyright (C) 2008-2019 TrinityCore <https://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by the
|
||||
* Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _ACORE_ERRORS_H_
|
||||
#define _ACORE_ERRORS_H_
|
||||
|
||||
#include "Define.h"
|
||||
#include <string>
|
||||
#include "StringFormat.h"
|
||||
|
||||
namespace Acore
|
||||
{
|
||||
[[noreturn]] void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message);
|
||||
[[noreturn]] void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message, char const* format, ...) ATTR_PRINTF(6, 7);
|
||||
// Default function
|
||||
[[noreturn]] AC_COMMON_API void Assert(std::string_view file, uint32 line, std::string_view function, std::string_view debugInfo, std::string_view message, std::string_view fmtMessage = {});
|
||||
[[noreturn]] AC_COMMON_API void Fatal(std::string_view file, uint32 line, std::string_view function, std::string_view message, std::string_view fmtMessage = {});
|
||||
[[noreturn]] AC_COMMON_API void Error(std::string_view file, uint32 line, std::string_view function, std::string_view message);
|
||||
[[noreturn]] AC_COMMON_API void Abort(std::string_view file, uint32 line, std::string_view function, std::string_view fmtMessage = {});
|
||||
|
||||
[[noreturn]] void Fatal(char const* file, int line, char const* function, char const* message, ...) ATTR_PRINTF(4, 5);
|
||||
template<typename... Args>
|
||||
AC_COMMON_API inline void Assert(std::string_view file, uint32 line, std::string_view function, std::string_view debugInfo, std::string_view message, std::string_view fmt, Args&&... args)
|
||||
{
|
||||
Assert(file, line, function, debugInfo, message, StringFormatFmt(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
[[noreturn]] void Error(char const* file, int line, char const* function, char const* message);
|
||||
template<typename... Args>
|
||||
AC_COMMON_API inline void Fatal(std::string_view file, uint32 line, std::string_view function, std::string_view message, std::string_view fmt, Args&&... args)
|
||||
{
|
||||
Fatal(file, line, function, message, StringFormatFmt(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
[[noreturn]] void Abort(char const* file, int line, char const* function);
|
||||
template<typename... Args>
|
||||
AC_COMMON_API inline void Abort(std::string_view file, uint32 line, std::string_view function, std::string_view fmt, Args&&... args)
|
||||
{
|
||||
Abort(file, line, function, StringFormatFmt(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
[[noreturn]] void Abort(char const* file, int line, char const* function, char const* message, ...);
|
||||
AC_COMMON_API void Warning(std::string_view file, uint32 line, std::string_view function, std::string_view message);
|
||||
|
||||
void Warning(char const* file, int line, char const* function, char const* message);
|
||||
|
||||
[[noreturn]] void AbortHandler(int sigval);
|
||||
[[noreturn]] AC_COMMON_API void AbortHandler(int sigval);
|
||||
|
||||
} // namespace Acore
|
||||
|
||||
std::string GetDebugInfo();
|
||||
AC_COMMON_API std::string GetDebugInfo();
|
||||
|
||||
#if AC_COMPILER == AC_COMPILER_MICROSOFT
|
||||
#define ASSERT_BEGIN __pragma(warning(push)) __pragma(warning(disable: 4127))
|
||||
#define ASSERT_END __pragma(warning(pop))
|
||||
#else
|
||||
#define ASSERT_BEGIN
|
||||
#define ASSERT_END
|
||||
#endif
|
||||
|
||||
#if AC_PLATFORM == AC_PLATFORM_WINDOWS
|
||||
#define EXCEPTION_ASSERTION_FAILURE 0xC0000420L
|
||||
#endif
|
||||
|
||||
#define WPAssert(cond, ...) ASSERT_BEGIN do { if (!(cond)) Acore::Assert(__FILE__, __LINE__, __FUNCTION__, GetDebugInfo(), #cond, ##__VA_ARGS__); } while(0) ASSERT_END
|
||||
#define WPAssert_NODEBUGINFO(cond, ...) ASSERT_BEGIN do { if (!(cond)) Acore::Assert(__FILE__, __LINE__, __FUNCTION__, "", #cond, ##__VA_ARGS__); } while(0) ASSERT_END
|
||||
#define WPFatal(cond, ...) ASSERT_BEGIN do { if (!(cond)) Acore::Fatal(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0) ASSERT_END
|
||||
#define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) Acore::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
|
||||
#define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) Acore::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
|
||||
#define WPAbort() ASSERT_BEGIN do { Acore::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END
|
||||
#define WPAbort_MSG(msg, ...) ASSERT_BEGIN do { Acore::Abort(__FILE__, __LINE__, __FUNCTION__, (msg), ##__VA_ARGS__); } while(0) ASSERT_END
|
||||
#define WPAssert(cond, ...) do { if (!(cond)) Acore::Assert(__FILE__, __LINE__, __FUNCTION__, GetDebugInfo(), #cond, ##__VA_ARGS__); } while(0)
|
||||
#define WPAssert_NODEBUGINFO(cond) do { if (!(cond)) Acore::Assert(__FILE__, __LINE__, __FUNCTION__, "", #cond); } while(0)
|
||||
#define WPFatal(cond, ...) do { if (!(cond)) Acore::Fatal(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0)
|
||||
#define WPError(cond, msg) do { if (!(cond)) Acore::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0)
|
||||
#define WPWarning(cond, msg) do { if (!(cond)) Acore::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0)
|
||||
#define WPAbort(...) do { Acore::Abort(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0)
|
||||
|
||||
#ifdef PERFORMANCE_PROFILING
|
||||
#define ASSERT(cond, ...) ((void)0)
|
||||
@@ -59,13 +69,16 @@ std::string GetDebugInfo();
|
||||
#define ASSERT_NODEBUGINFO WPAssert_NODEBUGINFO
|
||||
#endif
|
||||
|
||||
#if AC_PLATFORM == AC_PLATFORM_WINDOWS
|
||||
#define EXCEPTION_ASSERTION_FAILURE 0xC0000420L
|
||||
#endif
|
||||
|
||||
#define ABORT WPAbort
|
||||
#define ABORT_MSG WPAbort_MSG
|
||||
|
||||
template <typename T>
|
||||
inline T* ASSERT_NOTNULL_IMPL(T* pointer, char const* expr)
|
||||
inline T* ASSERT_NOTNULL_IMPL(T* pointer, std::string_view expr)
|
||||
{
|
||||
ASSERT(pointer, "%s", expr);
|
||||
ASSERT(pointer, "{}", expr);
|
||||
return pointer;
|
||||
}
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ std::vector<uint8> Field::GetBinary() const
|
||||
|
||||
void Field::GetBinarySizeChecked(uint8* buf, size_t length) const
|
||||
{
|
||||
ASSERT(data.value && (data.length == length), "Expected %zu-byte binary blob, got %sdata (%u bytes) instead", length, data.value ? "" : "no ", data.length);
|
||||
ASSERT(data.value && (data.length == length), "Expected {}-byte binary blob, got {}data ({} bytes) instead", length, data.value ? "" : "no ", data.length);
|
||||
memcpy(buf, data.value, length);
|
||||
}
|
||||
|
||||
|
||||
@@ -467,8 +467,8 @@ uint32 MySQLConnection::GetServerVersion() const
|
||||
|
||||
MySQLPreparedStatement* MySQLConnection::GetPreparedStatement(uint32 index)
|
||||
{
|
||||
ASSERT(index < m_stmts.size(), "Tried to access invalid prepared statement index %u (max index " SZFMTD ") on database `%s`, connection type: %s",
|
||||
index, m_stmts.size(), m_connectionInfo.database.c_str(), (m_connectionFlags & CONNECTION_ASYNC) ? "asynchronous" : "synchronous");
|
||||
ASSERT(index < m_stmts.size(), "Tried to access invalid prepared statement index {} (max index {}) on database `{}`, connection type: {}",
|
||||
index, m_stmts.size(), m_connectionInfo.database, (m_connectionFlags & CONNECTION_ASYNC) ? "asynchronous" : "synchronous");
|
||||
MySQLPreparedStatement* ret = m_stmts[index].get();
|
||||
if (!ret)
|
||||
LOG_ERROR("sql.sql", "Could not fetch prepared statement %u on database `%s`, connection type: %s.",
|
||||
|
||||
@@ -37,7 +37,7 @@ bool SQLQueryHolderBase::SetPreparedQueryImpl(size_t index, PreparedStatementBas
|
||||
PreparedQueryResult SQLQueryHolderBase::GetPreparedResult(size_t index) const
|
||||
{
|
||||
// Don't call to this function if the index is of a prepared statement
|
||||
ASSERT(index < m_queries.size(), "Query holder result index out of range, tried to access index " SZFMTD " but there are only " SZFMTD " results",
|
||||
ASSERT(index < m_queries.size(), "Query holder result index out of range, tried to access index {} but there are only {} results",
|
||||
index, m_queries.size());
|
||||
|
||||
return m_queries[index].second;
|
||||
|
||||
@@ -675,7 +675,7 @@ void Pet::Update(uint32 diff)
|
||||
if (owner->GetPetGUID() != GetGUID())
|
||||
{
|
||||
LOG_ERROR("entities.pet", "Pet %u is not pet of owner %s, removed", GetEntry(), GetOwner()->GetName().c_str());
|
||||
ASSERT(getPetType() != HUNTER_PET, "Unexpected unlinked pet found for owner %s", owner->GetSession()->GetPlayerInfo().c_str());
|
||||
ASSERT(getPetType() != HUNTER_PET, "Unexpected unlinked pet found for owner {}", owner->GetSession()->GetPlayerInfo());
|
||||
Remove(PET_SAVE_NOT_IN_SLOT);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,5 +66,5 @@ WorldPackets::PacketArrayMaxCapacityException::PacketArrayMaxCapacityException(s
|
||||
|
||||
void WorldPackets::CheckCompactArrayMaskOverflow(std::size_t index, std::size_t limit)
|
||||
{
|
||||
ASSERT(index < limit, "Attempted to insert " SZFMTD " values into CompactArray but it can only hold " SZFMTD, index, limit);
|
||||
ASSERT(index < limit, "Attempted to insert {} values into CompactArray but it can only hold {}", index, limit);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ char* DBCDatabaseLoader::Load(uint32& records, char**& indexTable)
|
||||
// Check if sql index pos is valid
|
||||
if (int32(result->GetFieldCount() - 1) < _sqlIndexPos)
|
||||
{
|
||||
ASSERT(false, "Invalid index pos for dbc: '%s'", _sqlTableName);
|
||||
ASSERT(false, "Invalid index pos for dbc: '{}'", _sqlTableName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -106,14 +106,14 @@ char* DBCDatabaseLoader::Load(uint32& records, char**& indexTable)
|
||||
case FT_NA:
|
||||
break;
|
||||
default:
|
||||
ASSERT(false, "Unsupported data type '%c' in table '%s'", *dbcFormat, _sqlTableName);
|
||||
ASSERT(false, "Unsupported data type '%c' in table '{}'", *dbcFormat, _sqlTableName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
++sqlColumnNumber;
|
||||
}
|
||||
|
||||
ASSERT(sqlColumnNumber == result->GetFieldCount(), "SQL format string does not match database for table: '%s'", _sqlTableName);
|
||||
ASSERT(sqlColumnNumber == result->GetFieldCount(), "SQL format string does not match database for table: '{}'", _sqlTableName);
|
||||
ASSERT(dataOffset == _recordSize);
|
||||
} while (result->NextRow());
|
||||
|
||||
|
||||
@@ -110,8 +110,8 @@ uint32 ByteBuffer::ReadPackedTime()
|
||||
|
||||
void ByteBuffer::append(uint8 const* src, size_t cnt)
|
||||
{
|
||||
ASSERT(src, "Attempted to put a NULL-pointer in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", _wpos, size());
|
||||
ASSERT(cnt, "Attempted to put a zero-sized value in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", _wpos, size());
|
||||
ASSERT(src, "Attempted to put a NULL-pointer in ByteBuffer (pos: {} size: {})", _wpos, size());
|
||||
ASSERT(cnt, "Attempted to put a zero-sized value in ByteBuffer (pos: {} size: {})", _wpos, size());
|
||||
ASSERT(size() < 10000000);
|
||||
|
||||
size_t const newSize = _wpos + cnt;
|
||||
@@ -143,9 +143,9 @@ void ByteBuffer::AppendPackedTime(time_t time)
|
||||
|
||||
void ByteBuffer::put(size_t pos, uint8 const* src, size_t cnt)
|
||||
{
|
||||
ASSERT(pos + cnt <= size(), "Attempted to put value with size: " SZFMTD " in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", cnt, pos, size());
|
||||
ASSERT(src, "Attempted to put a NULL-pointer in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", pos, size());
|
||||
ASSERT(cnt, "Attempted to put a zero-sized value in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", pos, size());
|
||||
ASSERT(pos + cnt <= size(), "Attempted to put value with size: {} in ByteBuffer (pos: {} size: {})", cnt, pos, size());
|
||||
ASSERT(src, "Attempted to put a NULL-pointer in ByteBuffer (pos: {} size: {})", pos, size());
|
||||
ASSERT(cnt, "Attempted to put a zero-sized value in ByteBuffer (pos: {} size: {})", pos, size());
|
||||
|
||||
std::memcpy(&_storage[pos], src, cnt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user