Skip to content

fix: Handle panic in ReadKey()#96

Open
liamg wants to merge 1 commit intoreeflective:masterfrom
liamg:fix/readkey-empty-input-panic
Open

fix: Handle panic in ReadKey()#96
liamg wants to merge 1 commit intoreeflective:masterfrom
liamg:fix/readkey-empty-input-panic

Conversation

@liamg
Copy link
Copy Markdown
Contributor

@liamg liamg commented Mar 15, 2026

Fix a panic in Vim character-search commands (f, F, t, T) when ReadKey() receives an empty read or EOF while waiting for the target character.

In that case, ReadKey() could attempt to index into an empty rune slice and panic. This surfaced downstream during interactive use.

What changed

internal/core/Keys.ReadKey() now:

  • handles empty reads without indexing into an empty buffer
  • treats EOF as an abort condition instead of panicking
  • continues waiting when a read returns no bytes but input has not ended

Tests

Added regression tests covering:

  • empty read followed by valid input
  • EOF returning an abort result without panicking

Why

Vim-style motions should fail gracefully if the follow-up character is unavailable; they should never crash the shell.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.84%. Comparing base (0637db4) to head (cd0f960).
⚠️ Report is 16 commits behind head on master.

Files with missing lines Patch % Lines
internal/core/keys.go 50.00% 11 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #96      +/-   ##
==========================================
- Coverage   33.03%   32.84%   -0.19%     
==========================================
  Files          57       58       +1     
  Lines        9109     9225     +116     
==========================================
+ Hits         3009     3030      +21     
- Misses       6062     6155      +93     
- Partials       38       40       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maxlandon
Copy link
Copy Markdown
Member

Thanks a lot your PR is awesome !!!

I definitely have to merge all your PRs, I will do this before the end of the month!

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