fix(ui): prevent status-bar panic on multi-byte error messages - #14
Open
svaiml wants to merge 1 commit into
Open
fix(ui): prevent status-bar panic on multi-byte error messages#14svaiml wants to merge 1 commit into
svaiml wants to merge 1 commit into
Conversation
The status bar truncates an overflowing status line with a byte slice at `center_width - 3`. When the status holds an error message containing multi-byte UTF-8 characters (GitHub API error bodies, GraphQL messages, org/repo names), that index can fall inside a character, so the slice panics with `byte index N is not a char boundary` and takes down the whole TUI draw loop, leaving the terminal in a broken raw state. Extract the truncation into `truncate_status`, which walks the cut point back to the nearest UTF-8 char boundary before appending the ellipsis. Behaviour is unchanged for ASCII status lines. Add unit tests covering the fit/no-truncation case, ASCII truncation, a cut that lands inside a multi-byte character, and a sweep over every width of a multi-byte-dense string to guarantee the path is panic-free. Signed-off-by: svaiml <88979468+svaiml@users.noreply.github.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.
Problem
render_status_bartruncates an overflowing status line with a raw byte slice:When the status line holds an error message, that message can contain multi-byte
UTF-8 characters — GitHub API error bodies, GraphQL error text, and org/repo
names all routinely do. If
center_width - 3falls inside such a character,the slice panics with
byte index N is not a char boundary. Because this runsinside the ratatui draw closure, the panic tears down the whole TUI and leaves
the terminal in a broken raw state.
The truncation branch triggers whenever
status.len() > center_width, i.e. on asufficiently narrow terminal (or a long error) — so a single non-ASCII byte in an
error message is enough to crash the app on the next frame.
Fix
Extract the truncation into a small
truncate_statushelper that walks the cutpoint back to the nearest UTF-8 character boundary before appending the ellipsis.
Behaviour is byte-for-byte identical for ASCII status lines; multi-byte lines are
now cut safely instead of panicking.
Tests
Added unit tests for:
panic-free.
cargo build --all-targets,cargo test,cargo clippy --all-targets -- -D warnings, andcargo fmt --checkall pass.