diff --git a/src/libs/image/impl/stb/RawImage.cpp b/src/libs/image/impl/stb/RawImage.cpp index 99021bf1..d18c967f 100644 --- a/src/libs/image/impl/stb/RawImage.cpp +++ b/src/libs/image/impl/stb/RawImage.cpp @@ -41,20 +41,41 @@ namespace lms::image::STB { + namespace + { + class StbiException : public Exception + { + public: + StbiException(std::string_view desc) + : Exception{ std::string{ desc } + ": " + getLastFailureReason() } + { + } + + private: + static std::string getLastFailureReason() + { + const char* failureReason{ ::stbi_failure_reason() }; + return failureReason ? failureReason : "unknown reason"; + } + }; + } // namespace + RawImage::RawImage(std::span encodedData) { int n{}; _data = UniquePtrFree{ ::stbi_load_from_memory(reinterpret_cast(encodedData.data()), encodedData.size(), &_width, &_height, &n, 3), std::free }; if (!_data) - throw Exception{ "Cannot load image from memory: " + std::string{ ::stbi_failure_reason() } }; + throw StbiException{ "Cannot load image from memory" }; } RawImage::RawImage(const std::filesystem::path& p) { int n{}; - _data = UniquePtrFree{ stbi_load(p.string().c_str(), &_width, &_height, &n, 3), std::free }; + _data = UniquePtrFree{ stbi_load(p.c_str(), &_width, &_height, &n, 3), std::free }; if (!_data) - throw Exception{ "Cannot load image from file: " + std::string{ ::stbi_failure_reason() } }; + { + throw StbiException{ "Cannot load image from file" }; + } } void RawImage::resize(ImageSize width) @@ -94,7 +115,7 @@ namespace lms::image::STB #error "Unhandled STB image resize version"! #endif { - throw Exception{ "Failed to resize image:" + std::string{ ::stbi_failure_reason() } }; + throw StbiException{ "Failed to resize image" }; } _data = std::move(resizedData); diff --git a/src/libs/services/scanner/impl/scanners/ImageFileScanner.cpp b/src/libs/services/scanner/impl/scanners/ImageFileScanner.cpp index 8f1278b8..216a51d5 100644 --- a/src/libs/services/scanner/impl/scanners/ImageFileScanner.cpp +++ b/src/libs/services/scanner/impl/scanners/ImageFileScanner.cpp @@ -77,7 +77,7 @@ namespace lms::scanner } catch (const image::Exception& e) { - LMS_LOG(DBUPDATER, ERROR, "Cannot read image in file '" << _file.string() << "': " << e.what()); + LMS_LOG(DBUPDATER, ERROR, "Cannot read image in file '" << _file.c_str() << "': " << e.what()); } }