Skip to content

Fix ValueError in _guess_lexer for single-line source files#4009

Closed
bysiber wants to merge 1 commit intoTextualize:masterfrom
bysiber:fix/traceback-guess-lexer-valueerror
Closed

Fix ValueError in _guess_lexer for single-line source files#4009
bysiber wants to merge 1 commit intoTextualize:masterfrom
bysiber:fix/traceback-guess-lexer-valueerror

Conversation

@bysiber
Copy link
Copy Markdown

@bysiber bysiber commented Feb 20, 2026

_guess_lexer uses str.index() to find the first newline in source code, but index() raises ValueError when the substring isn't found. The subsequent check if new_line_index != -1 only makes sense with str.find(), which returns -1 on miss.

When a traceback includes a frame from a single-line source file (no trailing newline), _guess_lexer crashes with an unhandled ValueError instead of rendering the traceback.

Changed code.index("\n")code.find("\n") so the existing -1 guard works as intended.

@willmcgugan
Copy link
Copy Markdown
Member

Your PR has been closed due to a AI policy violation.

Please read the following before submitting further PRs.

https://github.com/Textualize/textual/blob/main/AI_POLICY.md

@bysiber One more AI PR and you will be permanently banned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants