Repository navigation
🐛 Raise descriptive error when writing failed blocks without raw bibtex - #526
Merged
Merged
Conversation
…ex (#400) Failed blocks (e.g. DuplicateBlockKeyBlock) created programmatically have no raw bibtex, which previously crashed the writer with an opaque AttributeError. The writer now pre-scans the library and raises a single ValueError listing all such blocks, pointing users to library.failed_blocks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2 tasks
Collaborator
Author
|
reviewed |
MiWeiss
added a commit
that referenced
this pull request
Jun 12, 2026
After merging #526's tests into this branch, the duplicate must be added with fail_on_duplicate_key=False so the test still exercises the write-time error path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
MiWeiss
added a commit
that referenced
this pull request
Jun 12, 2026
* 🦖 Make Library.add fail on duplicate keys by default (#400) Programmatically adding an entry with an existing key previously replaced it silently with a DuplicateBlockKeyBlock, surprising users at write time (see #400). Library.add and the Library constructor now raise a ValueError on duplicate keys by default. Parsing behavior is unchanged: the splitter and middleware library reconstruction explicitly pass fail_on_duplicate_key=False, so bibtex files with duplicate keys still parse into library.failed_blocks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ♻️ Leave library untouched when add() raises on duplicate keys Instead of inserting the duplicate as a DuplicateBlockKeyBlock and then raising, add() now pre-checks all blocks (including duplicates within the same call) and raises before any mutation, making the operation atomic. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * 📝 Align add() docstring summary with fail-by-default behavior Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * remove unneeded comment * ✅ Adapt writer duplicate test to fail-by-default add() After merging #526's tests into this branch, the duplicate must be added with fail_on_duplicate_key=False so the test still exercises the write-time error path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- 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.
Context
Fixes the crash reported in #400: writing a library containing a
ParsingFailedBlockwhoserawisNone(e.g. aDuplicateBlockKeyBlockproduced by adding two programmatically created entries with the same key) failed with an opaqueAttributeError: 'NoneType' object has no attribute 'splitlines'.Change
The rule "failed block ⇒ write raw bibtex with a warning comment" is kept unchanged. When there is no raw bibtex, the writer no longer crashes but raises a single, actionable
ValueError:write()pre-scans the library and lists all offending blocks (with their errors) in one exception, so users can fix everything in one pass instead of replaying write-fail-fix.library.failed_blocksand suggests removing the blocks or fixing and re-addingblock.ignore_error_block._treat_failed_blockkeeps a backstop raise for direct callers.Refusing to write (rather than silently falling back to serializing
ignore_error_block) was discussed in #400: it loses no data, keeps the writer rule simple, and surfaces the duplicate-key bug to the user instead of shipping it downstream.A follow-up PR proposes flipping the
Library.adddefault tofail_on_duplicate_key=True, which would surface this class of error at theadd()call site already.🤖 Generated with Claude Code