Split error macro into two versions (format vs non-formating) to allow format checking at compile-time

This commit is contained in:
SirLynix
2023-11-02 15:18:03 +01:00
parent 8fb53f467b
commit 4b8a475bbd
133 changed files with 570 additions and 557 deletions

View File

@@ -179,7 +179,7 @@ namespace Nz
{
SocketError errorCode;
if (!SocketImpl::SetBlocking(m_handle, m_isBlockingEnabled, &errorCode))
NazaraWarning("failed to set socket blocking mode ({0:#x})", UnderlyingCast(errorCode));
NazaraWarningFmt("failed to set socket blocking mode ({0:#x})", UnderlyingCast(errorCode));
}
/*!
@@ -201,7 +201,7 @@ namespace Nz
{
SocketImpl::Close(handle);
NazaraError("failed to open a dual-stack socket: {0}", std::string(ErrorToString(m_lastError)));
NazaraErrorFmt("failed to open a dual-stack socket: {0}", ErrorToString(m_lastError));
return false;
}

View File

@@ -39,7 +39,7 @@ namespace Nz
if (!m_library.IsLoaded())
{
NazaraError("failed to load libcurl: {0}", m_library.GetLastError());
NazaraErrorFmt("failed to load libcurl: {0}", m_library.GetLastError());
return false;
}

View File

@@ -168,7 +168,7 @@ namespace Nz
if (peerCount > ENetConstants::ENetProtocol_MaximumPeerId)
{
NazaraError("peer count exceeds maximum peer count supported by protocol ({0})", UnderlyingCast(ENetConstants::ENetProtocol_MaximumPeerId));
NazaraErrorFmt("peer count exceeds maximum peer count supported by protocol ({0})", UnderlyingCast(ENetConstants::ENetProtocol_MaximumPeerId));
return false;
}
@@ -245,7 +245,7 @@ namespace Nz
return 1;
case -1:
NazaraError("Error sending outgoing packets");
NazaraError("error sending outgoing packets");
return -1;
default:
@@ -262,7 +262,7 @@ namespace Nz
return 1;
case -1:
//NazaraError("Error receiving incoming packets");
//NazaraError("error receiving incoming packets");
return -1;
default:
@@ -275,7 +275,7 @@ namespace Nz
return 1;
case -1:
NazaraError("Error sending outgoing packets");
NazaraError("error sending outgoing packets");
return -1;
@@ -338,7 +338,7 @@ namespace Nz
{
if (m_socket.Bind(address) != SocketState::Bound)
{
NazaraError("failed to bind address {0}", address.ToString());
NazaraErrorFmt("failed to bind address {0}", address.ToString());
return false;
}
}

View File

@@ -94,7 +94,7 @@ namespace Nz
return m_ipv6 == LoopbackIpV6.m_ipv6; // Only compare the ip value
}
NazaraInternalError("Invalid protocol for IpAddress ({0:#x})", UnderlyingCast(m_protocol));
NazaraInternalErrorFmt("invalid protocol for IpAddress ({0:#x})", UnderlyingCast(m_protocol));
return false;
}

View File

@@ -61,7 +61,7 @@ namespace Nz
if (epoll_ctl(m_handle, EPOLL_CTL_ADD, socket, &entry) != 0)
{
NazaraError("failed to add socket to epoll structure (errno {0}: {1})", errno, Error::GetLastSystemError());
NazaraErrorFmt("failed to add socket to epoll structure (errno {0}: {1})", errno, Error::GetLastSystemError());
return false;
}

View File

@@ -46,7 +46,7 @@ namespace Nz
std::size_t size = m_buffer->GetSize();
if (!EncodeHeader(m_buffer->GetBuffer(), static_cast<UInt32>(size), m_netCode))
{
NazaraError("Failed to encode packet header");
NazaraError("failed to encode packet header");
return nullptr;
}

View File

@@ -178,12 +178,12 @@ namespace Nz
}
default:
NazaraInternalError("Unhandled ip protocol ({0:#x})", UnderlyingCast(ipAddress.GetProtocol()));
NazaraInternalErrorFmt("unhandled ip protocol ({0:#x})", UnderlyingCast(ipAddress.GetProtocol()));
break;
}
}
NazaraError("Invalid ip address");
NazaraError("invalid ip address");
return 0;
}

View File

@@ -198,7 +198,7 @@ namespace Nz
if (waitError != SocketError::NoError)
{
if (waitError != SocketError::Interrupted) //< Do not log interrupted error
NazaraError("SocketPoller encountered an error (code: {0:#x}): {1}", UnderlyingCast(waitError), ErrorToString(waitError));
NazaraErrorFmt("SocketPoller encountered an error (code: {0:#x}): {1}", UnderlyingCast(waitError), ErrorToString(waitError));
return 0;
}

View File

@@ -187,7 +187,7 @@ namespace Nz
break;
}
NazaraInternalError("Unexpected socket state ({0:#x})", UnderlyingCast(m_state));
NazaraInternalErrorFmt("unexpected socket state ({0:#x})", UnderlyingCast(m_state));
return m_state;
}
@@ -426,7 +426,7 @@ namespace Nz
if (!ptr)
{
m_lastError = SocketError::Packet;
NazaraError("Failed to prepare packet");
NazaraError("failed to prepare packet");
return false;
}
@@ -479,7 +479,7 @@ namespace Nz
break;
}
NazaraInternalError("Unhandled socket state ({0:#x})", UnderlyingCast(m_state));
NazaraInternalErrorFmt("unhandled socket state ({0:#x})", UnderlyingCast(m_state));
return m_state;
}
@@ -516,10 +516,10 @@ namespace Nz
SocketError errorCode;
if (!SocketImpl::SetNoDelay(m_handle, m_isLowDelayEnabled, &errorCode))
NazaraWarning("failed to set socket no delay mode ({0:#x})", UnderlyingCast(errorCode));
NazaraWarningFmt("failed to set socket no delay mode ({0:#x})", UnderlyingCast(errorCode));
if (!SocketImpl::SetKeepAlive(m_handle, m_isKeepAliveEnabled, m_keepAliveTime, m_keepAliveInterval, &errorCode))
NazaraWarning("failed to set socket keep alive mode ({0:#x})", UnderlyingCast(errorCode));
NazaraWarningFmt("failed to set socket keep alive mode ({0:#x})", UnderlyingCast(errorCode));
m_peerAddress = IpAddress::Invalid;
m_openMode = OpenMode_ReadWrite;

View File

@@ -275,7 +275,7 @@ namespace Nz
if (!ptr)
{
m_lastError = SocketError::Packet;
NazaraError("Failed to prepare packet");
NazaraError("failed to prepare packet");
return false;
}

View File

@@ -277,7 +277,7 @@ namespace Nz
}
}
NazaraError("Invalid ip address");
NazaraError("invalid ip address");
return 0;
}

View File

@@ -160,7 +160,7 @@ namespace Nz
int errorCode = WSAStartup(MAKEWORD(2, 2), &s_WSA);
if (errorCode != 0)
{
NazaraError("failed to initialize Windows Socket 2.2: {0}", Error::GetLastSystemError(errorCode));
NazaraErrorFmt("failed to initialize Windows Socket 2.2: {0}", Error::GetLastSystemError(errorCode));
return false;
}

View File

@@ -91,7 +91,7 @@ namespace Nz
fd_set& targetSet = (i == 0) ? m_readSockets : m_writeSockets;
if (targetSet.fd_count > FD_SETSIZE)
{
NazaraError("Socket count exceeding hard-coded FD_SETSIZE ({0})", FD_SETSIZE);
NazaraErrorFmt("socket count exceeding hard-coded FD_SETSIZE ({0})", FD_SETSIZE);
return false;
}