Added hopefully more details in image parsing errors, ref #723

This commit is contained in:
emeric
2025-08-05 23:01:07 +02:00
parent 35ba66099f
commit 92a8194844
13 changed files with 41 additions and 33 deletions
@@ -41,12 +41,12 @@ namespace lms::image::GraphicsMagick
catch (Magick::Warning& e)
{
LMS_LOG(COVER, WARNING, "Caught Magick warning: " << e.what());
throw Exception{ std::string{ "Magick read warning: " } + e.what() };
throw Exception{ std::string{ "Read warning: " } + e.what() };
}
catch (Magick::Exception& e)
{
LMS_LOG(COVER, ERROR, "Caught Magick exception: " << e.what());
throw Exception{ std::string{ "Magick read error: " } + e.what() };
throw Exception{ std::string{ "Read error: " } + e.what() };
}
}
@@ -63,12 +63,12 @@ namespace lms::image::GraphicsMagick
catch (Magick::Warning& e)
{
LMS_LOG(COVER, WARNING, "Caught Magick warning: " << e.what());
throw Exception{ std::string{ "Magick read warning: " } + e.what() };
throw Exception{ std::string{ "Read warning: " } + e.what() };
}
catch (Magick::Exception& e)
{
LMS_LOG(COVER, ERROR, "Caught Magick exception: " << e.what());
throw Exception{ std::string{ "Magick read error: " } + e.what() };
throw Exception{ std::string{ "Read error: " } + e.what() };
}
}
@@ -93,7 +93,7 @@ namespace lms::image::GraphicsMagick
catch (Magick::Exception& e)
{
LMS_LOG(COVER, ERROR, "Caught Magick exception while resizing: " << e.what());
throw Exception{ std::string{ "Magick resize error: " } + e.what() };
throw Exception{ std::string{ "Resize error: " } + e.what() };
}
}
+9 -6
View File
@@ -23,14 +23,17 @@
namespace lms::image
{
StbiException::StbiException(std::string_view desc)
: Exception{ std::string{ desc } + ": " + getLastFailureReason() }
namespace
{
}
std::string getLastStbiFailureReason()
{
const char* failureReason{ ::stbi_failure_reason() };
return failureReason ? failureReason : "unknown reason";
}
} // namespace
std::string StbiException::getLastFailureReason()
StbiException::StbiException(std::string_view desc)
: Exception{ std::string{ desc } + ": " + getLastStbiFailureReason() }
{
const char* failureReason{ ::stbi_failure_reason() };
return failureReason ? failureReason : "unknown reason";
}
} // namespace lms::image
-3
View File
@@ -29,8 +29,5 @@ namespace lms::image
{
public:
StbiException(std::string_view desc);
private:
static std::string getLastFailureReason();
};
} // namespace lms::image
@@ -526,7 +526,7 @@ namespace lms::scanner
}
catch (const image::Exception& e)
{
addError<EmbeddedImageScanError>(getFilePath(), index);
addError<EmbeddedImageScanError>(getFilePath(), index, e.what());
}
index++;
@@ -62,7 +62,7 @@ namespace lms::scanner
catch (const image::Exception& e)
{
_parsedImageProperties.reset();
addError<ImageFileScanError>(getFilePath());
addError<ImageFileScanError>(getFilePath(), e.what());
}
}
@@ -43,7 +43,7 @@ namespace lms::scanner
void ScanErrorLogger::visit(const scanner::EmbeddedImageScanError& error)
{
LMS_LOG(DBUPDATER, ERROR, "Failed to parse image in track file " << error.path << " at index " << error.index);
LMS_LOG(DBUPDATER, ERROR, "Failed to parse image in track file " << error.path << " at index " << error.index << ": " << error.errorMsg);
}
void ScanErrorLogger::visit(const scanner::NoAudioTrackFoundError& error)
@@ -68,7 +68,7 @@ namespace lms::scanner
void ScanErrorLogger::visit(const scanner::ImageFileScanError& error)
{
LMS_LOG(DBUPDATER, ERROR, "Failed to read image file " << error.path);
LMS_LOG(DBUPDATER, ERROR, "Failed to read image file " << error.path << ": " << error.errorMsg);
}
void ScanErrorLogger::visit(const scanner::LyricsFileScanError& error)
@@ -95,9 +95,12 @@ namespace lms::scanner
struct EmbeddedImageScanError : public AudioFileScanError
{
EmbeddedImageScanError(const std::filesystem::path& p, unsigned i)
EmbeddedImageScanError(const std::filesystem::path& p, unsigned i, std::string_view e)
: AudioFileScanError{ p }
, index{ i } {}
, index{ i }
, errorMsg{ e }
{
}
void accept(ScanErrorVisitor& visitor) const override
{
@@ -105,6 +108,7 @@ namespace lms::scanner
}
unsigned index;
std::string errorMsg;
};
struct NoAudioTrackFoundError : public AudioFileScanError
@@ -149,12 +153,16 @@ namespace lms::scanner
struct ImageFileScanError : public ScanError
{
using ScanError::ScanError;
ImageFileScanError(const std::filesystem::path& p, std::string_view e)
: ScanError{ p }
, errorMsg{ e } {}
void accept(ScanErrorVisitor& visitor) const override
{
visitor.visit(*this);
}
std::string errorMsg;
};
struct LyricsFileScanError : public ScanError
+2 -2
View File
@@ -55,7 +55,7 @@ namespace lms::ui
}
void visit(const scanner::EmbeddedImageScanError& error) override
{
_os << error.path << ": " << Wt::WString::tr("Lms.Admin.ScannerController.bad-embedded-image").arg(error.index).toUTF8() << '\n';
_os << error.path << ": " << Wt::WString::tr("Lms.Admin.ScannerController.bad-embedded-image").arg(error.index).arg(Wt::WString::fromUTF8(error.errorMsg)).toUTF8() << '\n';
}
void visit(const scanner::NoAudioTrackFoundError& error) override
{
@@ -75,7 +75,7 @@ namespace lms::ui
}
void visit(const scanner::ImageFileScanError& error) override
{
_os << error.path << ": " << Wt::WString::tr("Lms.Admin.ScannerController.cannot-read-image-file").toUTF8() << '\n';
_os << error.path << ": " << Wt::WString::tr("Lms.Admin.ScannerController.cannot-read-image-file").arg(Wt::WString::fromUTF8(error.errorMsg)).toUTF8() << '\n';
}
void visit(const scanner::LyricsFileScanError& error) override
{