From 3f8dd2b3384c96cff7bf2f05ab545d57e899651b Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 10 Aug 2025 10:54:41 +0100 Subject: [PATCH] Add `no_ci_stop_if`, `no_ci_stop_damaged_if`, and `no_ci_warn_if` methods to enhance error and warning handling within `BaseHandle` and `QPDF`, highlighting that the error condition is not covered in CI testing without generating codecov noise. --- include/qpdf/ObjectHandle.hh | 4 ++++ include/qpdf/QPDF.hh | 2 ++ libqpdf/QPDF.cc | 2 +- libqpdf/qpdf/QPDFObjectHandle_private.hh | 27 +++++++++++++++++++++++++++ libqpdf/qpdf/QPDF_private.hh | 9 +++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/include/qpdf/ObjectHandle.hh b/include/qpdf/ObjectHandle.hh index 14951d1..0bafc31 100644 --- a/include/qpdf/ObjectHandle.hh +++ b/include/qpdf/ObjectHandle.hh @@ -127,6 +127,10 @@ namespace qpdf inline void assign(qpdf_object_type_e required, BaseHandle&& other); std::string description() const; + + void no_ci_warn_if(bool condition, std::string const& warning) const; + void no_ci_stop_if(bool condition, std::string const& warning) const; + void no_ci_stop_damaged_if(bool condition, std::string const& warning) const; std::invalid_argument invalid_error(std::string const& method) const; std::runtime_error type_error(char const* expected_type) const; QPDFExc type_error(char const* expected_type, std::string const& message) const; diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 23f910e..e82be88 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -874,6 +874,8 @@ class QPDF std::shared_ptr const& resolve(QPDFObjGen og); void resolveObjectsInStream(int obj_stream_number); void stopOnError(std::string const& message); + inline void + no_ci_stop_if(bool condition, std::string const& message, std::string const& context = {}); QPDFObjGen nextObjGen(); QPDFObjectHandle newIndirect(QPDFObjGen, std::shared_ptr const&); QPDFObjectHandle makeIndirectFromQPDFObject(std::shared_ptr const& obj); diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 6a6ffa7..1854427 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -946,7 +946,7 @@ QPDF::pipeForeignStreamData( } // Throw a generic exception when we lack context for something more specific. New code should not -// use this. This method exists to improve somewhat from calling assert in very old code. +// use this. void QPDF::stopOnError(std::string const& message) { diff --git a/libqpdf/qpdf/QPDFObjectHandle_private.hh b/libqpdf/qpdf/QPDFObjectHandle_private.hh index cca454d..41a1eef 100644 --- a/libqpdf/qpdf/QPDFObjectHandle_private.hh +++ b/libqpdf/qpdf/QPDFObjectHandle_private.hh @@ -624,6 +624,33 @@ namespace qpdf return obj ? obj->og.isIndirect() : false; } + inline void + BaseHandle::no_ci_stop_if(bool condition, std::string const& message) const + { + if (condition) { + if (qpdf()) { + throw QPDFExc(qpdf_e_damaged_pdf, "", description(), 0, message); + } + throw std::runtime_error(message); + } + } + + inline void + BaseHandle::no_ci_stop_damaged_if(bool condition, std::string const& message) const + { + if (condition) { + throw std::runtime_error(message); + } + } + + inline void + BaseHandle::no_ci_warn_if(bool condition, std::string const& warning) const + { + if (condition) { + warn(warning); + } + } + inline bool BaseHandle::null() const { diff --git a/libqpdf/qpdf/QPDF_private.hh b/libqpdf/qpdf/QPDF_private.hh index e0fc568..0fba51f 100644 --- a/libqpdf/qpdf/QPDF_private.hh +++ b/libqpdf/qpdf/QPDF_private.hh @@ -628,4 +628,13 @@ QPDF::page_labels() return *m->page_labels; } +// Throw a generic exception for unusual error conditions that do not be covered during CI testing. +inline void +QPDF::no_ci_stop_if(bool condition, std::string const& message, std::string const& context) +{ + if (condition) { + throw damagedPDF(context, message); + } +} + #endif // QPDF_PRIVATE_HH -- libgit2 0.21.4