fix(inspection): stop interpolating third-party messages into adapter errors - #40
Open
mazzasaverio wants to merge 1 commit into
Open
fix(inspection): stop interpolating third-party messages into adapter errors#40mazzasaverio wants to merge 1 commit into
mazzasaverio wants to merge 1 commit into
Conversation
… errors The PDF and Office adapters raised AdapterExecutionError with the underlying library's message embedded and the cause chained, so a failure on an invalid document surfaced the full file path (and, for pdfminer, possibly document fragments). In the contexts this package targets a path is itself sensitive: /home/user/clients/acme-holdings/payroll.docx names the client. Both adapters now raise fixed, format-naming messages with 'from None', matching the convention the engine and the built-in adapters already use. A regression test asserts that neither the directory name, the filename, nor the file content reaches the raised error. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The two new inspection adapters raise
AdapterExecutionError(f"...: {e}") from e, which puts the underlying library's message into the error text and keeps the cause chain. Everywhere else the codebase deliberately does the opposite: fixed strings plusfrom None(see_extract_document,_render_document, and the JSONL line error informats.py), and0.1.0a3even shipped a changelog entry named "Sanitized unsupported-format, decoding, parsing, rendering, and CLI failures".What that costs today, on a file that is not a valid DOCX:
The path alone can be sensitive in the contexts this package targets (a client name in a directory, a case number in a filename), and pdfminer messages can carry fragments of document content. Through
Pseudonymizer.inspect_filethe engine re-wraps these, so the leak is limited to direct adapter use, but the adapters are public and re-exported frompseudonymize.inspection.After this change:
A regression test builds a broken file under a directory named after a fictional client, with an email inside, and asserts that neither the path, nor the filename, nor the content appears in the raised error, and that the cause is suppressed the way the engine does it.
Two notes
from Nonesuppresses the context from tracebacks but does not clear__context__on the object, so the test asserts__cause__ is Noneand__suppress_context__rather than pretending the attribute disappears. This matches the existing convention exactly rather than inventing a stricter one.The two existing error-message tests were updated to the new wording.
Verification
Separate observation, not changed here because it touches the public exception surface: both adapters raise a bare
RuntimeErrorwhen the extra is missing, whileLocalONNXPIIBackendraisesImportErrorfor the same situation. Worth aligning, but that is your call on which of the two wins.🤖 Generated with Claude Code