Allow error message to be formatted
This commit is contained in:
committed by
Jérôme Leclercq
parent
25957c4b7f
commit
a741672a51
@@ -83,7 +83,7 @@ namespace Nz
|
||||
|
||||
if (byteStream.Read(ptr, byteCount) != byteCount)
|
||||
{
|
||||
NazaraError("Failed to read level #" + NumberToString(i));
|
||||
NazaraError("failed to read level #{0}", NumberToString(i));
|
||||
return Nz::Err(ResourceLoadingError::DecodingError);
|
||||
}
|
||||
|
||||
@@ -234,14 +234,14 @@ namespace Nz
|
||||
buf[3] = (header.format.fourCC >> 24) & 255;
|
||||
buf[4] = '\0';
|
||||
|
||||
NazaraError("Unhandled format \"" + std::string(buf) + "\"");
|
||||
NazaraError("unhandled format \"{0}\"", buf);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraError("Invalid DDS file");
|
||||
NazaraError("invalid DDS file");
|
||||
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: " + Error::GetLastError());
|
||||
NazaraError("failed to open stream from file: {0}", Error::GetLastError());
|
||||
return false;
|
||||
}
|
||||
m_ownedStream = std::move(file);
|
||||
|
||||
@@ -339,7 +339,7 @@ namespace Nz
|
||||
}
|
||||
else if (!hasGlobalColorTable)
|
||||
{
|
||||
NazaraError("corrupt gif (no color table for image #" + std::to_string(m_frames.size() - 1) + ")");
|
||||
NazaraError("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 (" + std::to_string(minimumCodeSize) + ")");
|
||||
NazaraError("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 0x" + NumberToString(label, 16) + ")");
|
||||
NazaraWarning("unrecognized extension label (unknown tag {0:#x})", label);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ namespace Nz
|
||||
}
|
||||
|
||||
default:
|
||||
NazaraError("corrupt gif (unknown tag 0x" + NumberToString(tag, 16) + ")");
|
||||
NazaraError("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: " + Error::GetLastError());
|
||||
NazaraError("failed to open stream from file: {0}", Error::GetLastError());
|
||||
return false;
|
||||
}
|
||||
m_ownedStream = std::move(file);
|
||||
|
||||
@@ -208,26 +208,26 @@ namespace Nz
|
||||
std::size_t frameCount = m_frames.size();
|
||||
if (frameCount == 0)
|
||||
{
|
||||
NazaraError("Frame count is invalid or missing");
|
||||
NazaraError("frame count is invalid or missing");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t jointCount = m_joints.size();
|
||||
if (jointCount == 0)
|
||||
{
|
||||
NazaraError("Joint count is invalid or missing");
|
||||
NazaraError("joint count is invalid or missing");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_frameIndex != frameCount)
|
||||
{
|
||||
NazaraError("Missing frame infos: [" + NumberToString(m_frameIndex) + ',' + NumberToString(frameCount) + ']');
|
||||
NazaraError("missing frame infos: [{0},{1}]", m_frameIndex, frameCount);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_frameRate == 0)
|
||||
{
|
||||
NazaraWarning("Framerate is either invalid or missing, assuming a default value of 24");
|
||||
NazaraWarning("framerate is either invalid or missing, assuming a default value of 24");
|
||||
m_frameRate = 24;
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ namespace Nz
|
||||
|
||||
void MD5AnimParser::Error(const std::string& message)
|
||||
{
|
||||
NazaraError(message + " at line #" + NumberToString(m_lineCount));
|
||||
NazaraError("{0} at line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
bool MD5AnimParser::ParseBaseframe()
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace Nz
|
||||
|
||||
void MD5MeshParser::Error(const std::string& message)
|
||||
{
|
||||
NazaraError(message + " at line #" + std::to_string(m_lineCount));
|
||||
NazaraError("{0} at line #1", message, m_lineCount);
|
||||
}
|
||||
|
||||
bool MD5MeshParser::ParseJoints()
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Nz
|
||||
File file(filePath);
|
||||
if (!file.Open(OpenMode::ReadOnly | OpenMode::Text))
|
||||
{
|
||||
NazaraError("Failed to open MTL file (" + file.GetPath().generic_u8string() + ')');
|
||||
NazaraError("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 \"" + matName + '"');
|
||||
NazaraWarning("MTL has no material \"{0}\"", matName);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ namespace Nz
|
||||
std::filesystem::path mtlLib = parser.GetMtlLib();
|
||||
if (!mtlLib.empty())
|
||||
{
|
||||
ErrorFlags flags(ErrorMode::ThrowExceptionDisabled);
|
||||
ErrorFlags errFlags({}, ~ErrorMode::ThrowException);
|
||||
ParseMTL(*mesh, stream.GetDirectory() / mtlLib, materials, meshes, meshCount);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,13 +65,13 @@ namespace Nz
|
||||
|
||||
if (!mesh.IsValid())
|
||||
{
|
||||
NazaraError("Invalid mesh");
|
||||
NazaraError("invalid mesh");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mesh.IsAnimable())
|
||||
{
|
||||
NazaraError("An animated mesh cannot be saved to " + format + " format");
|
||||
NazaraError("an animated mesh cannot be saved to {0} format", format);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Nz
|
||||
{
|
||||
if (!stream.Read(&rleValue, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')');
|
||||
NazaraError("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 " + NumberToString(stream.GetCursorPos()) + ')');
|
||||
NazaraError("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 " + NumberToString(stream.GetCursorPos()) + ')');
|
||||
NazaraError("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 " + NumberToString(stream.GetCursorPos()) + ')');
|
||||
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
|
||||
return Err(ResourceLoadingError::DecodingError);
|
||||
}
|
||||
}
|
||||
@@ -207,14 +207,14 @@ namespace Nz
|
||||
UInt8 magic;
|
||||
if (!stream.Read(&magic, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')');
|
||||
NazaraError("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 (0x" + NumberToString(magic, 16) + ')');
|
||||
NazaraError("Colormap's first byte must be 0x0c ({0:#x})", magic);
|
||||
return Err(ResourceLoadingError::DecodingError);
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ namespace Nz
|
||||
{
|
||||
if (!stream.Read(&rleValue, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')');
|
||||
NazaraError("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 " + NumberToString(stream.GetCursorPos()) + ')');
|
||||
NazaraError("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 " + NumberToString(stream.GetCursorPos()) + ')');
|
||||
NazaraError("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 " + NumberToString(stream.GetCursorPos()) + ')');
|
||||
NazaraError("failed to read stream (byte {0})", stream.GetCursorPos());
|
||||
return Err(ResourceLoadingError::DecodingError);
|
||||
}
|
||||
}
|
||||
@@ -311,7 +311,7 @@ namespace Nz
|
||||
}
|
||||
|
||||
default:
|
||||
NazaraError("Unsupported " + NumberToString(bitCount) + " bitcount for pcx files");
|
||||
NazaraError("unsupported {0} bitcount for pcx files", bitCount);
|
||||
return Err(ResourceLoadingError::DecodingError);
|
||||
}
|
||||
|
||||
|
||||
@@ -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: " + std::string(stbi_failure_reason()));
|
||||
NazaraError("failed to load image: {0}", std::string(stbi_failure_reason()));
|
||||
return Err(ResourceLoadingError::DecodingError);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,13 +113,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_bmp_to_func(&WriteToStream, &stream, tempImage.GetWidth(), tempImage.GetHeight(), componentCount, tempImage.GetConstPixels()))
|
||||
{
|
||||
NazaraError("Failed to write BMP to stream");
|
||||
NazaraError("failed to write BMP to stream");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -133,20 +133,20 @@ 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;
|
||||
}
|
||||
|
||||
long long imageQuality = parameters.custom.GetIntegerParameter("JPEGQuality").GetValueOr(100);
|
||||
if (imageQuality <= 0 || imageQuality > 100)
|
||||
{
|
||||
NazaraError("NativeJPEGSaver_Quality value (" + Nz::NumberToString(imageQuality) + ") does not fit in bounds ]0, 100], clamping...");
|
||||
NazaraError("NativeJPEGSaver_Quality value ({0}) does not fit in bounds ]0, 100], clamping...", imageQuality);
|
||||
imageQuality = Nz::Clamp(imageQuality, 1LL, 100LL);
|
||||
}
|
||||
|
||||
if (!stbi_write_jpg_to_func(&WriteToStream, &stream, tempImage.GetWidth(), tempImage.GetHeight(), componentCount, tempImage.GetConstPixels(), int(imageQuality)))
|
||||
{
|
||||
NazaraError("Failed to write JPEG to stream");
|
||||
NazaraError("failed to write JPEG to stream");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ namespace Nz
|
||||
ImageType type = image.GetType();
|
||||
if (type != ImageType::E1D && type != ImageType::E2D)
|
||||
{
|
||||
NazaraError("Image type 0x" + NumberToString(UnderlyingCast(type), 16) + " is not in a supported format");
|
||||
NazaraError("Image type {0:#x}) is not in a supported format", UnderlyingCast(type));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user