Fix crash on Windows: guard POSIX-only SIGWINCH trap#123
Open
freyazh wants to merge 1 commit into
Open
Conversation
TrySelector#setup_terminal trapped SIGWINCH unconditionally. On Windows
Ruby (x64-mingw-ucrt) SIGWINCH isn't a supported signal, so
Signal.trap('WINCH') raises `ArgumentError: unsupported signal 'SIGWINCH'`
the instant the picker opens, aborting before the TUI renders.
Trap it only when the platform has it (`Signal.list.key?('WINCH')`). WINCH
is the only signal trapped and restore_terminal is already nil-guarded, so
teardown is unaffected; POSIX behaviour (including live-resize redraw) is
unchanged. Adds a Minitest that stubs Signal.list to assert setup_terminal
doesn't raise when WINCH is absent.
Co-Authored-By: Claude Opus 4.8 (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.
Problem
On Windows,
trycrashes the instant the interactive picker opens:SIGWINCHis POSIX-only — it isn't in the Windows signal set, soSignal.listhas no
'WINCH'key andSignal.trap('WINCH')raisesArgumentError.TrySelector#setup_terminaltraps it unconditionally, so the process dies beforethe TUI renders. This hits any Windows Ruby (
RUBY_PLATFORM=x64-mingw-ucrt/mingw / mswin). The README says try "works on any system with Ruby" and the gem
declares no platform restriction, so Windows is in scope.
Fix
Trap
WINCHonly where the platform actually has it:WINCHis the only signaltrytraps, and the restore site inrestore_terminalis already nil-guarded(
Signal.trap('WINCH', @old_winch_handler) if @old_winch_handler, with@old_winch_handler = nilset ininitialize). On Windows the guard leaves@old_winch_handlernil, so teardown is a clean no-op and nothing regresses. OnPOSIX,
Signal.list.key?('WINCH')is true and behaviour is unchanged — no loss,including live-resize redraw. Using
Signal.list.key?('WINCH')rather thanGem.win_platform?keeps it a portable "trap only if the signal exists" check.Scope / testing
Deliberately minimal — just the crash. Verified on
x64-mingw-ucrtRuby thatSignal.list.key?('WINCH')isfalseand the picker now reachessetup_terminalwithout raising. CI here is Linux-only (whereWINCHexists),so this path can't be exercised there; the guard is a no-op on the tested
platforms.
Follow-up (intentionally not in this PR): once the crash is gone, the
picker's input loop still assumes a POSIX console —
IO.select([STDIN]),STDIN.read_nonblock,STDIN.iflush, andIO.console.winsize(which raisesErrno::EBADFwhen stderr isn't a real console). Making the interactive pickerfully functional on Windows is separate work; PR #70's "full parity" attempt
took a non-Ruby route and was closed. Keeping this to the one-line crash guard so
it's easy to accept.