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

@@ -83,7 +83,7 @@ namespace Nz
if (byteStream.Read(ptr, byteCount) != byteCount)
{
NazaraError("failed to read level #{0}", NumberToString(i));
NazaraErrorFmt("failed to read level #{0}", i);
return Nz::Err(ResourceLoadingError::DecodingError);
}
@@ -111,7 +111,7 @@ namespace Nz
{
if (header.ddsCaps[1] & DDSCAPS2_CUBEMAP)
{
NazaraError("Cubemap arrays are not yet supported, sorry");
NazaraError("cubemap arrays are not yet supported, sorry");
return false;
}
else if (header.flags & DDSD_HEIGHT)
@@ -125,7 +125,7 @@ namespace Nz
{
if ((header.ddsCaps[1] & DDSCAPS2_CUBEMAP_ALLFACES) != DDSCAPS2_CUBEMAP_ALLFACES)
{
NazaraError("Partial cubemap are not yet supported, sorry");
NazaraError("partial cubemap are not yet supported, sorry");
return false;
}
@@ -133,7 +133,7 @@ namespace Nz
}
else if (headerExt.resourceDimension == D3D10_RESOURCE_DIMENSION_BUFFER)
{
NazaraError("Texture buffers are not yet supported, sorry");
NazaraError("texture buffers are not yet supported, sorry");
return false;
}
else if (headerExt.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE1D)
@@ -234,7 +234,7 @@ namespace Nz
buf[3] = (header.format.fourCC >> 24) & 255;
buf[4] = '\0';
NazaraError("unhandled format \"{0}\"", buf);
NazaraErrorFmt("unhandled format \"{0}\"", buf);
return false;
}
}

View File

@@ -75,7 +75,7 @@ namespace Nz
{
if (FT_Stroker_New(s_freetypeLibrary, &s_freetypeStroker) != 0)
{
NazaraWarning("Failed to load FreeType stroker, outline will not be possible");
NazaraWarning("failed to load FreeType stroker, outline will not be possible");
s_freetypeStroker = nullptr; //< Just in case
}
}
@@ -114,7 +114,7 @@ namespace Nz
#ifdef NAZARA_DEBUG
if (!dst)
{
NazaraError("Glyph destination cannot be null");
NazaraError("glyph destination cannot be null");
return false;
}
#endif
@@ -123,7 +123,7 @@ namespace Nz
if (FT_Load_Char(m_face, character, FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_NORMAL) != 0)
{
NazaraError("Failed to load character");
NazaraError("failed to load character");
return false;
}
@@ -132,7 +132,7 @@ namespace Nz
FT_Glyph glyph;
if (FT_Get_Glyph(glyphSlot, &glyph) != 0)
{
NazaraError("Failed to extract glyph");
NazaraError("failed to extract glyph");
return false;
}
CallOnExit destroyGlyph([&]() { FT_Done_Glyph(glyph); });
@@ -152,7 +152,7 @@ namespace Nz
FT_OutlineGlyph outlineGlyph = reinterpret_cast<FT_OutlineGlyph>(glyph);
if (FT_Outline_Embolden(&outlineGlyph->outline, boldStrength) != 0)
{
NazaraError("Failed to embolden glyph");
NazaraError("failed to embolden glyph");
return false;
}
}
@@ -162,7 +162,7 @@ namespace Nz
FT_Stroker_Set(s_freetypeStroker, static_cast<FT_Fixed>(s_freetypeScaleFactor * outlineThickness), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);
if (FT_Glyph_Stroke(&glyph, s_freetypeStroker, 1) != 0)
{
NazaraError("Failed to outline glyph");
NazaraError("failed to outline glyph");
return false;
}
}
@@ -170,7 +170,7 @@ namespace Nz
if (FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, nullptr, 1) != 0)
{
NazaraError("Failed to convert glyph to bitmap");
NazaraError("failed to convert glyph to bitmap");
return false;
}
@@ -320,7 +320,7 @@ namespace Nz
std::unique_ptr<File> file = std::make_unique<File>();
if (!file->Open(filePath, OpenMode::ReadOnly))
{
NazaraError("failed to open stream from file: {0}", Error::GetLastError());
NazaraErrorFmt("failed to open stream from file: {0}", Error::GetLastError());
return false;
}
m_ownedStream = std::move(file);
@@ -392,7 +392,7 @@ namespace Nz
std::unique_ptr<FreeTypeStream> face = std::make_unique<FreeTypeStream>();
if (!face->SetFile(filePath))
{
NazaraError("Failed to open file");
NazaraError("failed to open file");
return Err(ResourceLoadingError::FailedToOpenFile);
}

View File

@@ -339,7 +339,7 @@ namespace Nz
}
else if (!hasGlobalColorTable)
{
NazaraError("corrupt gif (no color table for image #{0}", m_frames.size() - 1);
NazaraErrorFmt("corrupt gif (no color table for image #{0}", m_frames.size() - 1);
return Err(ResourceLoadingError::DecodingError);
}
@@ -347,7 +347,7 @@ namespace Nz
m_byteStream >> minimumCodeSize;
if (minimumCodeSize > 12)
{
NazaraError("unexpected LZW Minimum Code Size ({0})", minimumCodeSize);
NazaraErrorFmt("unexpected LZW Minimum Code Size ({0})", minimumCodeSize);
return Err(ResourceLoadingError::DecodingError);
}
@@ -410,7 +410,7 @@ namespace Nz
break;
default:
NazaraWarning("unrecognized extension label (unknown tag {0:#x})", label);
NazaraWarningFmt("unrecognized extension label (unknown tag {0:#x})", label);
break;
}
@@ -419,7 +419,7 @@ namespace Nz
}
default:
NazaraError("corrupt gif (unknown tag {0:#x})", tag);
NazaraErrorFmt("corrupt gif (unknown tag {0:#x})", tag);
return Err(ResourceLoadingError::DecodingError);
}
}
@@ -450,7 +450,7 @@ namespace Nz
std::unique_ptr<File> file = std::make_unique<File>();
if (!file->Open(filePath, OpenMode::ReadOnly))
{
NazaraError("failed to open stream from file: {0}", Error::GetLastError());
NazaraErrorFmt("failed to open stream from file: {0}", Error::GetLastError());
return false;
}
m_ownedStream = std::move(file);

View File

@@ -64,7 +64,7 @@ namespace Nz
if (stream.GetSize() < header.offset_end)
{
NazaraError("Incomplete MD2 file");
NazaraError("incomplete MD2 file");
return Err(ResourceLoadingError::DecodingError);
}

View File

@@ -221,7 +221,7 @@ namespace Nz
if (m_frameIndex != frameCount)
{
NazaraError("missing frame infos: [{0},{1}]", m_frameIndex, frameCount);
NazaraErrorFmt("missing frame infos: [{0},{1}]", m_frameIndex, frameCount);
return false;
}
@@ -264,7 +264,7 @@ namespace Nz
void MD5AnimParser::Error(const std::string& message)
{
NazaraError("{0} at line #{1}", message, m_lineCount);
NazaraErrorFmt("{0} at line #{1}", message, m_lineCount);
}
bool MD5AnimParser::ParseBaseframe()

View File

@@ -119,7 +119,7 @@ namespace Nz
if (!ParseMesh())
{
NazaraError("Failed to parse mesh");
NazaraError("failed to parse mesh");
return false;
}
@@ -211,7 +211,7 @@ namespace Nz
void MD5MeshParser::Error(const std::string& message)
{
NazaraError("{0} at line #1", message, m_lineCount);
NazaraErrorFmt("{0} at line #1", message, m_lineCount);
}
bool MD5MeshParser::ParseJoints()
@@ -237,7 +237,7 @@ namespace Nz
if (pos >= 64)
{
NazaraError("Joint name is too long (>= 64 characters)");
NazaraError("joint name is too long (>= 64 characters)");
return false;
}
@@ -420,19 +420,19 @@ namespace Nz
if (m_meshes[m_meshIndex].triangles.empty())
{
NazaraError("Mesh has no triangles");
NazaraError("mesh has no triangles");
return false;
}
if (m_meshes[m_meshIndex].vertices.empty())
{
NazaraError("Mesh has no vertices");
NazaraError("mesh has no vertices");
return false;
}
if (m_meshes[m_meshIndex].weights.empty())
{
NazaraError("Mesh has no weights");
NazaraError("mesh has no weights");
return false;
}

View File

@@ -32,7 +32,7 @@ namespace Nz
File file(filePath);
if (!file.Open(OpenMode::ReadOnly | OpenMode::Text))
{
NazaraError("failed to open MTL file ({0})", file.GetPath());
NazaraErrorFmt("failed to open MTL file ({0})", file.GetPath());
return false;
}
@@ -51,7 +51,7 @@ namespace Nz
const MTLParser::Material* mtlMat = materialParser.GetMaterial(matName);
if (!mtlMat)
{
NazaraWarning("MTL has no material \"{0}\"", matName);
NazaraWarningFmt("MTL has no material \"{0}\"", matName);
continue;
}

View File

@@ -478,7 +478,7 @@ namespace Nz
if (m_meshes.empty())
{
NazaraError("No meshes");
NazaraError("no meshes");
return false;
}

View File

@@ -71,7 +71,7 @@ namespace Nz
if (mesh.IsAnimable())
{
NazaraError("an animated mesh cannot be saved to {0} format", format);
NazaraErrorFmt("an animated mesh cannot be saved to {0} format", format);
return false;
}

View File

@@ -76,7 +76,7 @@ namespace Nz
std::shared_ptr<Image> image = std::make_shared<Image>();
if (!image->Create(ImageType::E2D, PixelFormat::RGB8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1))
{
NazaraError("Failed to create image");
NazaraError("failed to create image");
return Err(ResourceLoadingError::Internal);
}
@@ -101,7 +101,7 @@ namespace Nz
{
if (!stream.Read(&rleValue, 1))
{
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
NazaraErrorFmt("failed to read stream (byte {0})", stream.GetCursorPos());
return Err(ResourceLoadingError::DecodingError);
}
@@ -112,7 +112,7 @@ namespace Nz
rleCount = rleValue - 0xc0;
if (!stream.Read(&rleValue, 1))
{
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
NazaraErrorFmt("failed to read stream (byte {0})", stream.GetCursorPos());
return Err(ResourceLoadingError::DecodingError);
}
}
@@ -156,7 +156,7 @@ namespace Nz
{
if (!stream.Read(&rleValue, 1))
{
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
NazaraErrorFmt("failed to read stream (byte {0})", stream.GetCursorPos());
return Err(ResourceLoadingError::DecodingError);
}
@@ -167,7 +167,7 @@ namespace Nz
rleCount = rleValue - 0xc0;
if (!stream.Read(&rleValue, 1))
{
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
NazaraErrorFmt("failed to read stream (byte {0})", stream.GetCursorPos());
return Err(ResourceLoadingError::DecodingError);
}
}
@@ -207,21 +207,21 @@ namespace Nz
UInt8 magic;
if (!stream.Read(&magic, 1))
{
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
NazaraErrorFmt("failed to read stream (byte {0})", stream.GetCursorPos());
return Err(ResourceLoadingError::DecodingError);
}
/* first byte must be equal to 0x0c (12) */
if (magic != 0x0c)
{
NazaraError("Colormap's first byte must be 0x0c ({0:#x})", magic);
NazaraErrorFmt("Colormap's first byte must be 0x0c ({0:#x})", magic);
return Err(ResourceLoadingError::DecodingError);
}
/* read palette */
if (stream.Read(palette, 768) != 768)
{
NazaraError("Failed to read palette");
NazaraError("failed to read palette");
return Err(ResourceLoadingError::DecodingError);
}
@@ -240,7 +240,7 @@ namespace Nz
{
if (!stream.Read(&rleValue, 1))
{
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
NazaraErrorFmt("failed to read stream (byte {0})", stream.GetCursorPos());
return Err(ResourceLoadingError::DecodingError);
}
@@ -251,7 +251,7 @@ namespace Nz
rleCount = rleValue - 0xc0;
if (!stream.Read(&rleValue, 1))
{
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
NazaraErrorFmt("failed to read stream (byte {0})", stream.GetCursorPos());
return Err(ResourceLoadingError::DecodingError);
}
}
@@ -284,7 +284,7 @@ namespace Nz
{
if (!stream.Read(&rleValue, 1))
{
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
NazaraErrorFmt("failed to read stream (byte {0})", stream.GetCursorPos());
return Err(ResourceLoadingError::DecodingError);
}
@@ -295,7 +295,7 @@ namespace Nz
rleCount = rleValue - 0xc0;
if (!stream.Read(&rleValue, 1))
{
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
NazaraErrorFmt("failed to read stream (byte {0})", stream.GetCursorPos());
return Err(ResourceLoadingError::DecodingError);
}
}
@@ -311,7 +311,7 @@ namespace Nz
}
default:
NazaraError("unsupported {0} bitcount for pcx files", bitCount);
NazaraErrorFmt("unsupported {0} bitcount for pcx files", bitCount);
return Err(ResourceLoadingError::DecodingError);
}

View File

@@ -64,7 +64,7 @@ namespace Nz
UInt8* ptr = stbi_load_from_callbacks(&s_stbiCallbacks, &stream, &width, &height, &bpp, STBI_rgb_alpha);
if (!ptr)
{
NazaraError("failed to load image: {0}", std::string(stbi_failure_reason()));
NazaraErrorFmt("failed to load image: {0}", std::string(stbi_failure_reason()));
return Err(ResourceLoadingError::DecodingError);
}
@@ -76,7 +76,7 @@ namespace Nz
std::shared_ptr<Image> image = std::make_shared<Image>();
if (!image->Create(ImageType::E2D, PixelFormat::RGBA8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1))
{
NazaraError("Failed to create image");
NazaraError("failed to create image");
return Err(ResourceLoadingError::Internal);
}
@@ -88,7 +88,7 @@ namespace Nz
{
if (!image->Convert(parameters.loadFormat))
{
NazaraError("Failed to convert image to required format");
NazaraError("failed to convert image to required format");
return Err(ResourceLoadingError::Internal);
}
}

View File

@@ -101,7 +101,7 @@ namespace Nz
{
Stream* stream = static_cast<Stream*>(userdata);
if (stream->Write(data, size) != static_cast<std::size_t>(size))
throw std::runtime_error("Failed to write to stream");
throw std::runtime_error("failed to write to stream");
}
bool SaveBMP(const Image& image, const ImageParams& parameters, Stream& stream)
@@ -140,7 +140,7 @@ namespace Nz
long long imageQuality = parameters.custom.GetIntegerParameter("JPEGQuality").GetValueOr(100);
if (imageQuality <= 0 || imageQuality > 100)
{
NazaraError("NativeJPEGSaver_Quality value ({0}) does not fit in bounds ]0, 100], clamping...", imageQuality);
NazaraErrorFmt("NativeJPEGSaver_Quality value ({0}) does not fit in bounds ]0, 100], clamping...", imageQuality);
imageQuality = Nz::Clamp(imageQuality, 1LL, 100LL);
}
@@ -162,13 +162,13 @@ namespace Nz
int componentCount = ConvertToFloatFormat(tempImage);
if (componentCount == 0)
{
NazaraError("Failed to convert image to suitable format");
NazaraError("failed to convert image to suitable format");
return false;
}
if (!stbi_write_hdr_to_func(&WriteToStream, &stream, tempImage.GetWidth(), tempImage.GetHeight(), componentCount, reinterpret_cast<const float*>(tempImage.GetConstPixels())))
{
NazaraError("Failed to write HDR to stream");
NazaraError("failed to write HDR to stream");
return false;
}
@@ -184,13 +184,13 @@ namespace Nz
int componentCount = ConvertToIntegerFormat(tempImage);
if (componentCount == 0)
{
NazaraError("Failed to convert image to suitable format");
NazaraError("failed to convert image to suitable format");
return false;
}
if (!stbi_write_png_to_func(&WriteToStream, &stream, tempImage.GetWidth(), tempImage.GetHeight(), componentCount, tempImage.GetConstPixels(), 0))
{
NazaraError("Failed to write PNG to stream");
NazaraError("failed to write PNG to stream");
return false;
}
@@ -206,13 +206,13 @@ namespace Nz
int componentCount = ConvertToIntegerFormat(tempImage);
if (componentCount == 0)
{
NazaraError("Failed to convert image to suitable format");
NazaraError("failed to convert image to suitable format");
return false;
}
if (!stbi_write_tga_to_func(&WriteToStream, &stream, tempImage.GetWidth(), tempImage.GetHeight(), componentCount, tempImage.GetConstPixels()))
{
NazaraError("Failed to write TGA to stream");
NazaraError("failed to write TGA to stream");
return false;
}
@@ -241,14 +241,14 @@ namespace Nz
if (!image.IsValid())
{
NazaraError("Invalid image");
NazaraError("invalid image");
return false;
}
ImageType type = image.GetType();
if (type != ImageType::E1D && type != ImageType::E2D)
{
NazaraError("Image type {0:#x}) is not in a supported format", UnderlyingCast(type));
NazaraErrorFmt("Image type {0:#x}) is not in a supported format", UnderlyingCast(type));
return false;
}