Merge pull request #1386 from siddharthgaur1/fix-blank-pdfminer-exception

Surface wrapped exception class name in blank PdfminerException messages
This commit is contained in:
Jeremy Singer-Vine
2026-07-30 23:13:17 -04:00
committed by GitHub
4 changed files with 18 additions and 1 deletions
+1
View File
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. The format
### Fixed
- Initialize PDFium's form environment in `get_page_image` so that filled AcroForm field content is included when rendering pages via `Page.to_image()`. ([#1367](https://github.com/jsvine/pdfplumber/issues/1367))
- Include the wrapped exception's class name in `PdfminerException`'s message when `pdfminer.six` raises an exception without one (e.g. `PDFPasswordIncorrect`), which previously surfaced as a blank error message.
## [0.11.10] — 2026-06-14
+1
View File
@@ -576,6 +576,7 @@ Many thanks to the following users who've contributed ideas, features, and fixes
- [Anton Ilin](https://github.com/bronislav)
- [Sebastian Cao](https://github.com/cycsmail)
- [Kaspar Naraghi](https://github.com/kaninaba94)
- [Siddharth Gaur](https://github.com/siddharthgaur1)
## Contributing
+8 -1
View File
@@ -3,4 +3,11 @@ class MalformedPDFException(Exception):
class PdfminerException(Exception):
pass
def __str__(self) -> str:
msg = super().__str__()
if not msg and self.args and isinstance(self.args[0], BaseException):
# pdfminer.six raises some exceptions without a message (e.g.
# PDFPasswordIncorrect), which would otherwise be surfaced here
# as a blank error message.
return type(self.args[0]).__name__
return msg
+8
View File
@@ -192,6 +192,14 @@ class Test(unittest.TestCase):
with pdfplumber.open(path, password="test") as pdf:
assert len(pdf.chars) > 0
def test_missing_password_message(self):
# pdfminer.six raises some exceptions without a message, which would
# otherwise be re-raised here as a blank PdfminerException.
path = os.path.join(HERE, "pdfs/password-example.pdf")
with pytest.raises(pdfplumber.utils.exceptions.PdfminerException) as exc:
pdfplumber.open(path)
assert "PDFPasswordIncorrect" in str(exc.value)
def test_unicode_normalization(self):
path = os.path.join(HERE, "pdfs/issue-905.pdf")