🐛 Fix misleading 'Unknown block type' warning for failed blocks and add missing DuplicateFieldKeyBlock.entry (#520)#523
Merged
Conversation
BlockMiddleware.transform_block did not recognize ParsingFailedBlock and its subtypes (e.g. DuplicateFieldKeyBlock), causing a confusing 'Unknown block type' warning with the default parse stack whenever an entry contained duplicate field keys. Failed blocks are now passed through silently via an overridable `transform_failed_block` hook. Also adds the `entry` property on DuplicateFieldKeyBlock, which the error message promised but which did not exist, and documents the failed-block types in the quickstart and API docs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
language-formatters-pre-commit-hooks v2.12.0 and docstr_coverage v2.3.0 crash on import in current CI environments (ModuleNotFoundError: pkg_resources). Both dropped the pkg_resources dependency in their latest releases. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Instead of adding the `entry` alias promised by the (wrong) error message, fix the message to reference `ignore_error_block`, keeping the failed-block API consistent across all ParsingFailedBlock subtypes. Co-Authored-By: Claude Fable 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.
Fixes #520
What was wrong
As reported in #520, parsing a bib file containing an entry with duplicate field keys produced the confusing warning
and offered no documented way to inspect the problem. Three distinct issues were behind this:
BlockMiddleware.transform_blockhad no branch forParsingFailedBlockand its subtypes, so any block middleware (includingRemoveEnclosingMiddlewarefrom the default parse stack) fell through to the "Unknown block type" warning for every failed block — even though these are well-known model types that are intentionally passed through.DuplicateFieldKeyBlockerror message told users the entry is "available asfailed_block.entry", but no such attribute exists — the entry is available asfailed_block.ignore_error_block. This is the "another problem shadowing correct behavior" suspected in the issue discussion.Changes
BlockMiddlewarenow handlesParsingFailedBlockexplicitly via a new overridabletransform_failed_blockhook, which by default keeps failed blocks unchanged (and silent). Custom middlewares can override it if they want to process failed blocks.DuplicateFieldKeyBlockerror message to reference the existingignore_error_blockattribute (consistent with the otherParsingFailedBlocksubtypes), instead of the non-existent.entry.ParsingFailedBlock,MiddlewareErrorBlock,DuplicateBlockKeyBlockandDuplicateFieldKeyBlockin the API docs, addedLibrary.failed_blocksto theLibrarydocs, and expanded the quickstart error-checking section with the available attributes (error,start_line,raw,ignore_error_block, ...).language-formatters-pre-commit-hooks,docstr_coverage) whose pinned versions crash in current CI environments withModuleNotFoundError: No module named 'pkg_resources'; their latest releases dropped thepkg_resourcesdependency.BlockMiddlewareunchanged without any warning;DuplicateFieldKeyBlock.duplicate_keysand the corrected error message are asserted in the splitter tests.Before / after
Before: logs
Unknown block type <class 'bibtexparser.model.DuplicateFieldKeyBlock'>; the error message points tofailed_block.entry, which raisesAttributeError.After: no warning; the error message points to
failed_block.ignore_error_block, which returns the entry including bothtitlefields, andlib.failed_blocks[0].duplicate_keys == {"title"}.Full test suite passes (2475 passed, 12 skipped), pre-commit hooks pass.
🤖 Generated with Claude Code