Repository navigation
Recover iterator panics in indexed TTY formatters and DelegatingLexer - #1502
Merged
alecthomas merged 1 commit intoNov 21, 2026
Merged
alecthomas merged 1 commit into
alecthomas merged 1 commit into
Conversation
alecthomas
approved these changes
Nov 21, 2026
alecthomas
enabled auto-merge (squash)
November 21, 2026 05:49
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.
Problem
Commit a69d1c0 changed
RegexLexerto surface regex match errors (such as the 250msMatchTimeout) by panicking from the token iterator soFormatter.Formatcan recover and return anerror. Following #1500, two code paths still let iterator panics escape unrecovered:formatters.TTY(terminal),TTY8(terminal8),TTY16(terminal16), andTTY256(terminal256) implementFormattervia*indexedTTYFormatterwithout panic recovery, crashing callers instead of returning an error.DelegatingLexer.Tokeniseeagerly consumesd.language's token iterator insideTokenisebefore returning(iter.Seq[Token], error)(prior toFormatter.Format), so a panic from the embedded language lexer crashes callers such asquick.Highlightandplayground.Highlightinstead of returning an error.Root cause
indexedTTYFormatter.Formatinformatters/tty_indexed.gobypassedchroma.FormatterFuncand lackedrecover().(*delegatingLexer).Tokeniseindelegate.goranges overlanguageTokenssynchronously while buildingrootText, before anyFormatterrecovery frame is on the call stack.Fix
indexedTTYFormatterinchroma.FormatterFunc, matchingTTY16mand the other function-backed formatters so every registered formatter recovers iterator panics uniformly.(*delegatingLexer).Tokeniseso panics during the eagerlanguageTokenspass are returned aserror.Tests
TestFormattersRecoverIteratorPanicinformatters/tty_indexed_test.goexercising every registered formatter informatters.Names()with both string anderrorpanics.TestDelegateRecoversLanguageIteratorPanicindelegate_test.goverifying botherrorand string panics in the embedded language lexer are returned fromTokenise.