Commit 3f8dd2b3384c96cff7bf2f05ab545d57e899651b
1 parent
f6d8da10
Add `no_ci_stop_if`, `no_ci_stop_damaged_if`, and `no_ci_warn_if` methods to enh…
…ance error and warning handling within `BaseHandle` and `QPDF`, highlighting that the error condition is not covered in CI testing without generating codecov noise.
Showing
5 changed files
with
43 additions
and
1 deletions
include/qpdf/ObjectHandle.hh
| ... | ... | @@ -127,6 +127,10 @@ namespace qpdf |
| 127 | 127 | inline void assign(qpdf_object_type_e required, BaseHandle&& other); |
| 128 | 128 | |
| 129 | 129 | std::string description() const; |
| 130 | + | |
| 131 | + void no_ci_warn_if(bool condition, std::string const& warning) const; | |
| 132 | + void no_ci_stop_if(bool condition, std::string const& warning) const; | |
| 133 | + void no_ci_stop_damaged_if(bool condition, std::string const& warning) const; | |
| 130 | 134 | std::invalid_argument invalid_error(std::string const& method) const; |
| 131 | 135 | std::runtime_error type_error(char const* expected_type) const; |
| 132 | 136 | QPDFExc type_error(char const* expected_type, std::string const& message) const; | ... | ... |
include/qpdf/QPDF.hh
| ... | ... | @@ -874,6 +874,8 @@ class QPDF |
| 874 | 874 | std::shared_ptr<QPDFObject> const& resolve(QPDFObjGen og); |
| 875 | 875 | void resolveObjectsInStream(int obj_stream_number); |
| 876 | 876 | void stopOnError(std::string const& message); |
| 877 | + inline void | |
| 878 | + no_ci_stop_if(bool condition, std::string const& message, std::string const& context = {}); | |
| 877 | 879 | QPDFObjGen nextObjGen(); |
| 878 | 880 | QPDFObjectHandle newIndirect(QPDFObjGen, std::shared_ptr<QPDFObject> const&); |
| 879 | 881 | QPDFObjectHandle makeIndirectFromQPDFObject(std::shared_ptr<QPDFObject> const& obj); | ... | ... |
libqpdf/QPDF.cc
| ... | ... | @@ -946,7 +946,7 @@ QPDF::pipeForeignStreamData( |
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | // Throw a generic exception when we lack context for something more specific. New code should not |
| 949 | -// use this. This method exists to improve somewhat from calling assert in very old code. | |
| 949 | +// use this. | |
| 950 | 950 | void |
| 951 | 951 | QPDF::stopOnError(std::string const& message) |
| 952 | 952 | { | ... | ... |
libqpdf/qpdf/QPDFObjectHandle_private.hh
| ... | ... | @@ -624,6 +624,33 @@ namespace qpdf |
| 624 | 624 | return obj ? obj->og.isIndirect() : false; |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | + inline void | |
| 628 | + BaseHandle::no_ci_stop_if(bool condition, std::string const& message) const | |
| 629 | + { | |
| 630 | + if (condition) { | |
| 631 | + if (qpdf()) { | |
| 632 | + throw QPDFExc(qpdf_e_damaged_pdf, "", description(), 0, message); | |
| 633 | + } | |
| 634 | + throw std::runtime_error(message); | |
| 635 | + } | |
| 636 | + } | |
| 637 | + | |
| 638 | + inline void | |
| 639 | + BaseHandle::no_ci_stop_damaged_if(bool condition, std::string const& message) const | |
| 640 | + { | |
| 641 | + if (condition) { | |
| 642 | + throw std::runtime_error(message); | |
| 643 | + } | |
| 644 | + } | |
| 645 | + | |
| 646 | + inline void | |
| 647 | + BaseHandle::no_ci_warn_if(bool condition, std::string const& warning) const | |
| 648 | + { | |
| 649 | + if (condition) { | |
| 650 | + warn(warning); | |
| 651 | + } | |
| 652 | + } | |
| 653 | + | |
| 627 | 654 | inline bool |
| 628 | 655 | BaseHandle::null() const |
| 629 | 656 | { | ... | ... |
libqpdf/qpdf/QPDF_private.hh
| ... | ... | @@ -628,4 +628,13 @@ QPDF::page_labels() |
| 628 | 628 | return *m->page_labels; |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | +// Throw a generic exception for unusual error conditions that do not be covered during CI testing. | |
| 632 | +inline void | |
| 633 | +QPDF::no_ci_stop_if(bool condition, std::string const& message, std::string const& context) | |
| 634 | +{ | |
| 635 | + if (condition) { | |
| 636 | + throw damagedPDF(context, message); | |
| 637 | + } | |
| 638 | +} | |
| 639 | + | |
| 631 | 640 | #endif // QPDF_PRIVATE_HH | ... | ... |