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

@@ -76,7 +76,7 @@ namespace Nz
return std::make_unique<WhirlpoolHasher>();
}
NazaraInternalError("Hash type not handled ({0:#x})", UnderlyingCast(type));
NazaraInternalErrorFmt("Hash type not handled ({0:#x})", UnderlyingCast(type));
return nullptr;
}
}

View File

@@ -119,6 +119,6 @@ namespace Nz
void ByteStream::OnEmptyStream()
{
NazaraError("No stream");
NazaraError("no stream");
}
}

View File

@@ -76,7 +76,7 @@ namespace Nz
auto impl = std::make_unique<DynLibImpl>();
if (!impl->Load(libraryPath, &m_lastError))
{
NazaraError("failed to load library: {0}", m_lastError);
NazaraErrorFmt("failed to load library: {0}", m_lastError);
return false;
}

View File

@@ -192,7 +192,7 @@ namespace Nz
if (!impl->Open(m_filePath, openMode))
{
ErrorFlags flags(ErrorMode::Silent); // Silent by default
NazaraError("failed to open \"{0}\": {1}", m_filePath, Error::GetLastSystemError());
NazaraErrorFmt("failed to open \"{0}\": {1}", m_filePath, Error::GetLastSystemError());
return false;
}
@@ -243,7 +243,7 @@ namespace Nz
std::unique_ptr<FileImpl> impl = std::make_unique<FileImpl>(this);
if (!impl->Open(filePath, m_openMode))
{
NazaraError("failed to open new file; {0}", Error::GetLastSystemError());
NazaraErrorFmt("failed to open new file; {0}", Error::GetLastSystemError());
return false;
}
@@ -268,8 +268,8 @@ namespace Nz
if (!CheckFileOpening())
return false;
NazaraAssert(IsOpen(), "File is not open");
NazaraAssert(IsWritable(), "File is not writable");
NazaraAssert(IsOpen(), "file is not open");
NazaraAssert(IsWritable(), "file is not writable");
return m_impl->SetSize(size);
}
@@ -281,7 +281,7 @@ namespace Nz
File file(path);
if (!file.Open(OpenMode::ReadOnly | OpenMode::Unbuffered)) //< unbuffered since we will read all the file at once
{
NazaraError("failed to open \"{0}\"", path);
NazaraErrorFmt("failed to open \"{0}\"", path);
return std::nullopt;
}
@@ -301,7 +301,7 @@ namespace Nz
File file(path);
if (!file.Open(OpenMode::WriteOnly | OpenMode::Unbuffered)) //< unbuffered since we will write all the file at once
{
NazaraError("failed to open \"{0}\"", path);
NazaraErrorFmt("failed to open \"{0}\"", path);
return false;
}
@@ -455,7 +455,7 @@ namespace Nz
File file(originalFile.GetPath());
if (!file.Open(OpenMode::ReadOnly))
{
NazaraError("Unable to open file");
NazaraError("unable to open file");
return false;
}
@@ -467,7 +467,7 @@ namespace Nz
std::size_t size = std::min<std::size_t>(static_cast<std::size_t>(remainingSize), NAZARA_CORE_FILE_BUFFERSIZE);
if (file.Read(&buffer[0], size) != size)
{
NazaraError("Unable to read file");
NazaraError("unable to read file");
return false;
}

View File

@@ -113,7 +113,7 @@ namespace Nz
m_outputFile.open(m_outputPath, std::ios_base::trunc | std::ios_base::out);
if (!m_outputFile.is_open())
{
NazaraError("Failed to open output file");
NazaraError("failed to open output file");
return;
}
}

View File

@@ -613,7 +613,7 @@ namespace Nz
break;
default:
NazaraError("Split heuristic out of enum ({0:#x})", UnderlyingCast(method));
NazaraErrorFmt("split heuristic out of enum ({0:#x})", UnderlyingCast(method));
splitHorizontal = true;
}
@@ -658,7 +658,7 @@ namespace Nz
return ScoreWorstShortSideFit(width, height, freeRect);
}
NazaraError("Rect choice heuristic out of enum ({0:#x})", UnderlyingCast(rectChoice));
NazaraErrorFmt("Rect choice heuristic out of enum ({0:#x})", UnderlyingCast(rectChoice));
return std::numeric_limits<int>::max();
}
}

View File

@@ -46,7 +46,7 @@ namespace Nz
void FileImpl::Flush()
{
if (fsync(m_fileDescriptor) == -1)
NazaraError("Unable to flush file: {0}", Error::GetLastSystemError());
NazaraErrorFmt("unable to flush file: {0}", Error::GetLastSystemError());
}
UInt64 FileImpl::GetCursorPos() const
@@ -81,7 +81,7 @@ namespace Nz
int fileDescriptor = Open_def(filePath.generic_u8string().data(), flags, permissions);
if (fileDescriptor == -1)
{
NazaraError("Failed to open \"{0}\": {1}", filePath, Error::GetLastSystemError());
NazaraErrorFmt("failed to open \"{0}\": {1}", filePath, Error::GetLastSystemError());
return false;
}
@@ -101,14 +101,14 @@ namespace Nz
if (fcntl(fileDescriptor, F_GETLK, &lock) == -1)
{
close(fileDescriptor);
NazaraError("Unable to detect presence of lock on the file");
NazaraError("unable to detect presence of lock on the file");
return false;
}
if (lock.l_type != F_UNLCK)
{
close(fileDescriptor);
NazaraError("A lock is present on the file");
NazaraError("a lock is present on the file");
return false;
}
@@ -119,7 +119,7 @@ namespace Nz
if (fcntl(fileDescriptor, F_SETLK, &lock) == -1)
{
close(fileDescriptor);
NazaraError("Unable to place a lock on the file");
NazaraError("unable to place a lock on the file");
return false;
}
}
@@ -161,7 +161,7 @@ namespace Nz
break;
default:
NazaraInternalError("Cursor position not handled ({0:#x})", UnderlyingCast(pos));
NazaraInternalErrorFmt("cursor position not handled ({0:#x})", UnderlyingCast(pos));
return false;
}

View File

@@ -20,7 +20,7 @@ namespace Nz
#if NAZARA_CORE_SAFE
if (workerCount == 0)
{
NazaraError("Invalid worker count ! (0)");
NazaraError("invalid worker count ! (0)");
return false;
}
#endif
@@ -74,7 +74,7 @@ namespace Nz
#ifdef NAZARA_CORE_SAFE
if (s_workerCount == 0)
{
NazaraError("Task scheduler is not initialized");
NazaraError("task scheduler is not initialized");
return;
}
#endif
@@ -106,7 +106,7 @@ namespace Nz
#ifdef NAZARA_CORE_SAFE
if (s_workerCount == 0)
{
NazaraError("Task scheduler is not initialized");
NazaraError("task scheduler is not initialized");
return;
}
#endif

View File

@@ -82,7 +82,7 @@ namespace Nz
#if NAZARA_CORE_SAFE
if (m_referenceCount == 0)
{
NazaraError("Impossible to remove reference (Ref. counter is already 0)");
NazaraError("impossible to remove reference (Ref. counter is already 0)");
return false;
}
#endif

View File

@@ -278,7 +278,7 @@ namespace Nz
void* Stream::GetMemoryMappedPointer() const
{
NazaraError("Stream set the MemoryMapped option but did not implement GetMemoryMappedPointer");
NazaraError("stream set the MemoryMapped option but did not implement GetMemoryMappedPointer");
return nullptr;
}

View File

@@ -202,7 +202,7 @@ namespace Nz
}
catch (utf8::exception& e)
{
NazaraError("UTF-8 error: {0}", e.what());
NazaraErrorFmt("UTF-8 error: {0}", e.what());
}
catch (std::exception& e)
{

View File

@@ -62,7 +62,7 @@ namespace Nz
{
if (!Initialize())
{
NazaraError("Failed to initialize Task Scheduler");
NazaraError("failed to initialize Task Scheduler");
return;
}
@@ -86,7 +86,7 @@ namespace Nz
#ifdef NAZARA_CORE_SAFE
if (TaskSchedulerImpl::IsInitialized())
{
NazaraError("Worker count cannot be set while initialized");
NazaraError("worker count cannot be set while initialized");
return;
}
#endif
@@ -114,7 +114,7 @@ namespace Nz
{
if (!Initialize())
{
NazaraError("Failed to initialize Task Scheduler");
NazaraError("failed to initialize Task Scheduler");
return;
}
@@ -134,7 +134,7 @@ namespace Nz
{
if (!Initialize())
{
NazaraError("Failed to initialize Task Scheduler");
NazaraError("failed to initialize Task Scheduler");
return;
}

View File

@@ -43,7 +43,7 @@ namespace Nz
void FileImpl::Flush()
{
if (!FlushFileBuffers(m_handle))
NazaraError("Unable to flush file: {0}", Error::GetLastSystemError());
NazaraErrorFmt("Unable to flush file: {0}", Error::GetLastSystemError());
}
UInt64 FileImpl::GetCursorPos() const
@@ -153,7 +153,7 @@ namespace Nz
break;
default:
NazaraInternalError("Cursor position not handled ({0:#x})", UnderlyingCast(pos));
NazaraInternalErrorFmt("cursor position not handled ({0:#x})", UnderlyingCast(pos));
return false;
}
@@ -172,18 +172,18 @@ namespace Nz
CallOnExit resetCursor([this, cursorPos] ()
{
if (!SetCursorPos(CursorPosition::AtBegin, cursorPos))
NazaraWarning("Failed to reset cursor position to previous position: " + Error::GetLastSystemError());
NazaraWarningFmt("Failed to reset cursor position to previous position: {0}", Error::GetLastSystemError());
});
if (!SetCursorPos(CursorPosition::AtBegin, size))
{
NazaraError("failed to set file size: failed to move cursor position: {0}", Error::GetLastSystemError());
NazaraErrorFmt("failed to set file size: failed to move cursor position: {0}", Error::GetLastSystemError());
return false;
}
if (!SetEndOfFile(m_handle))
{
NazaraError("failed to set file size: {0}", Error::GetLastSystemError());
NazaraErrorFmt("failed to set file size: {0}", Error::GetLastSystemError());
return false;
}

View File

@@ -19,7 +19,7 @@ namespace Nz
#if NAZARA_CORE_SAFE
if (workerCount == 0)
{
NazaraError("Invalid worker count ! (0)");
NazaraError("invalid worker count ! (0)");
return false;
}
#endif
@@ -90,7 +90,7 @@ namespace Nz
#ifdef NAZARA_CORE_SAFE
if (s_workerCount == 0)
{
NazaraError("Task scheduler is not initialized");
NazaraError("task scheduler is not initialized");
return;
}
#endif
@@ -137,7 +137,7 @@ namespace Nz
#ifdef NAZARA_CORE_SAFE
if (s_workerCount == 0)
{
NazaraError("Task scheduler is not initialized");
NazaraError("task scheduler is not initialized");
return;
}
#endif