Fix crash loop on bib entries with the cite key on its own line - #31
Open
pevab wants to merge 1 commit into
Open
Fix crash loop on bib entries with the cite key on its own line#31pevab wants to merge 1 commit into
pevab wants to merge 1 commit into
Conversation
BibTeX does not require the cite key to share a line with "@type{", and OpenReview's "Cite" export puts it on the next line: @inproceedings{ key2025, title={x} } parse_type() matches the remainder of the "@type{" line against [[\v^([^, ]*)\s*,\s*(.*)]], which requires both the key and a comma. On such an entry the remainder is empty, matchlist() returns {}, and matches[2] / matches[3] are both nil. The `self.empty(matches[3])` guard should catch that, but empty() has no branch for a nil argument and falls through returning nil, so the guard fails open. parse_entry() is then called with nil, and cmp_vimtex#count() raises E706 (its try/catch only handles E712). Because indexing runs on a repeating timer, the uncaught error aborts the callback before timer:stop() is reached, so it fires again and again, cascading into "table index is nil" at self.result[v.cite_key] and then arithmetic on a nil self.lnum. One such entry makes the session unusable. Fix by deferring the cite-key lookup to parse_entry() when parse_type() cannot find it, and by returning true from empty() for nil so the existing guards behave as intended. Verified against a 55-entry bibliography containing one such entry: it now indexes cleanly and produces a key set identical to the one the unpatched parser produces after the entry is reformatted onto one line. Fixes micangl#29 Co-Authored-By: Claude Opus 5 (1M context) <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 #29.
Reproducer
BibTeX does not require the cite key to share a line with
@type{, and this is exactly what OpenReview's "Cite" button exports — so it shows up in a lot of ML bibliographies. BibTeX itself accepts it, so it goes unnoticed until the editor falls over.Cause
parse_type()matches the remainder of the@type{line against[[\v^([^, ]*)\s*,\s*(.*)]], which requires both the key and a comma. On the entry above the remainder is"", somatchlist()returns{}andmatches[2]/matches[3]are bothnil.The
self.empty(matches[3])guard is meant to catch that, butempty()has no branch fornil— it teststype(list) == "table"and== "string"and otherwise falls off the end returningnil. The guard fails open,parse_entry(self, nil)runs, andcmp_vimtex#count(v:null, '{')raisesE706(thetry/catchthere only handlesE712).Why it loops
Indexing runs on a repeating 50 ms timer, and the uncaught error aborts the callback before
self.timer:stop()is reached. The timer keeps firing over progressively more damaged state, so a single bad entry produces an unbounded cascade of three alternating errors:The change
Two parts, both needed:
parse_entry()picks up the cite key from the first subsequent line that supplies one, whenparse_type()couldn't find it.empty()returnstruefornil, so the existing guards behave as intended.Part 2 alone is not sufficient — I tested it. It silences the
E706but the entry is still stored withcite_key = nil, which just moves the crash toparser.lua:144and the loop continues.Verification
Against a real 55-entry bibliography containing one such entry, and a well-formed control:
E706)The key sets from both patched runs are identical to what the unpatched parser produces on the well-formed file, so well-formed bibliographies are unaffected.
Separate suggestion, not in this PR
Independently of this parse bug, it may be worth wrapping the timer callback in a
pcallthat stops the timer on error. Right now any unexpected parse failure takes out the whole session rather than just the offending entry, which is what turned this into a hard crash instead of one skipped entry. Happy to add it here or open it separately if you'd like.🤖 Generated with Claude Code