fix(formats): reject inspection-only formats before doing the work - #39
Open
mazzasaverio wants to merge 1 commit into
Open
fix(formats): reject inspection-only formats before doing the work#39mazzasaverio wants to merge 1 commit into
mazzasaverio wants to merge 1 commit into
Conversation
process_file returned the inspection adapter as both input and output adapter for PDF and Office documents, so the engine extracted the whole document and ran detection over every block before render() failed and was reported as a generic 'output adapter failed during rendering'. Nothing indicated that these formats are inspection-only. They are now rejected up front with UnsupportedFormatError naming inspect_file. Two related edges: inspect_file silently ignored 'encoding' for those formats, and BuiltinFileAdapter accepted them and fell through to the CSV branch, decoding binary documents as UTF-8 text. Both now raise. A shared INSPECTION_ONLY_FORMATS set keeps the list in one place. 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
Three rough edges in the new
0.3.0format plumbing, all reachable from normal use. None of them changes what the adapters extract; they change what happens on paths that cannot work.1.
process_fileon a PDF or Office document did all the work, then failed obscurely._processing_adaptersreturned the inspection adapter as both input and output adapter, so the engine extracted the document, ran detection over every block, and only then hitrender(), whoseAdapterContractErrorwas swallowed by_render_documentand re-raised as:Nothing tells the caller that these formats are inspection-only, or that
inspect_fileis what they want. Now the format is rejected up front:2.
inspect_file(..., encoding=...)silently ignored the encoding for PDF and Office. Elsewhere the engine is strict about meaningless combinations (custom adapters cannot be combined with format or encoding), so this now raises rather than pretending the argument had an effect.3.
BuiltinFileAdapteraccepted the new binary formats.FileFormatgainedPDF/DOCX/XLSX/PPTX, but the adapter's dispatch chain ends in an unconditionalelsethat parses CSV, soBuiltinFileAdapter(FileFormat.PDF).extract(path)tried to decode a PDF as UTF-8 text and died withUnicodeDecodeError. It now refuses at construction. The engine no longer routes those formats there, so this is defence in depth rather than an active bug.A shared
INSPECTION_ONLY_FORMATSfrozenset informats.pyis the single place that lists them, so adding a format to the enum no longer requires remembering three separate call sites.Note on the two updated tests
test_process_pdf_failsandtest_process_docx_failsasserted the old message, so they now assert the new one plus the absence of a partial output file. The exception type changes fromAdapterExecutionErrortoUnsupportedFormatErroron that path; both derive fromPseudonymizeError, soexcept PseudonymizeErrorcallers are unaffected, and this surface shipped hours ago in0.3.0.Verification
Related to #38, which covers the larger question of which document regions the adapters read.
🤖 Generated with Claude Code