vcl/source/pdf/PDFiumLibrary.cxx |   32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

New commits:
commit 807f977b389f196d17701f01ddbb40b297face95
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Dec 23 12:02:12 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Mon Dec 23 15:21:59 2024 +0100

    pdfium: Log error when opening fails (useful for tests)
    
    Change-Id: I597d82bb40c73b900c08c8b37fd303e8f5e98eed
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179179
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index f48d02595453..d2d91e88bb9a 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -495,6 +495,7 @@ private:
     PDFiumImpl& operator=(const PDFiumImpl&) = delete;
 
     OUString maLastError;
+    void setLastError(OUString const& rErrorString);
 
 public:
     PDFiumImpl();
@@ -522,10 +523,21 @@ PDFiumImpl::PDFiumImpl()
 
 PDFiumImpl::~PDFiumImpl() { FPDF_DestroyLibrary(); }
 
+void PDFiumImpl::setLastError(OUString const& rErrorString)
+{
+    if (!rErrorString.isEmpty())
+    {
+        // Report what error was set (useful in test failures)
+        SAL_WARN("vcl.filter", "PDFiumImpl Error: '" << rErrorString << "' 
Error numner: "
+                                                     << 
sal_Int32(getLastErrorCode()));
+    }
+    maLastError = rErrorString;
+}
+
 std::unique_ptr<PDFiumDocument> PDFiumImpl::openDocument(const void* pData, 
int nSize,
                                                          const OString& 
rPassword)
 {
-    maLastError = OUString();
+    setLastError(u""_ustr);
     std::unique_ptr<PDFiumDocument> pPDFiumDocument;
 
     FPDF_BYTESTRING pPassword = nullptr;
@@ -540,27 +552,28 @@ std::unique_ptr<PDFiumDocument> 
PDFiumImpl::openDocument(const void* pData, int
         switch (FPDF_GetLastError())
         {
             case FPDF_ERR_SUCCESS:
-                maLastError = "Success";
+                setLastError(u"Success"_ustr);
                 break;
             case FPDF_ERR_UNKNOWN:
-                maLastError = "Unknown error";
+                setLastError(u"Unknown error"_ustr);
                 break;
             case FPDF_ERR_FILE:
-                maLastError = "File not found";
+                setLastError(u"File not found"_ustr);
                 break;
             case FPDF_ERR_FORMAT:
-                maLastError = "Input is not a PDF format";
+                setLastError(u"Input is not a PDF format"_ustr);
                 break;
             case FPDF_ERR_PASSWORD:
-                maLastError = "Incorrect password or password is required";
+                setLastError(u"Incorrect password or password is 
required"_ustr);
                 break;
             case FPDF_ERR_SECURITY:
-                maLastError = "Security error";
+                setLastError(u"Security error"_ustr);
                 break;
             case FPDF_ERR_PAGE:
-                maLastError = "Content error";
+                setLastError(u"Content error"_ustr);
                 break;
             default:
+                setLastError(u"Unknown error number"_ustr);
                 break;
         }
     }
@@ -605,8 +618,7 @@ std::unique_ptr<PDFiumBitmap> PDFiumImpl::createBitmap(int& 
nWidth, int& nHeight
 
     if (!pPdfBitmap)
     {
-        maLastError = "Failed to create bitmap";
-        SAL_WARN("vcl.filter", "PDFiumImpl: " << getLastError());
+        setLastError(u"Failed to create bitmap"_ustr);
     }
     else
     {

Reply via email to