Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some operations throwing the exception reline/ansi.rb:246:in `winsize': Operation not supported by device - <STDIN> (Errno::ENODEV) #690

Closed
vtamara opened this issue Apr 26, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@vtamara
Copy link
Contributor

vtamara commented Apr 26, 2024

Description

On OpenBSD/adJ 7.4 on a tmux session the exception Errno::ENODEV is thrown in the following scenario:

  1. In a rails project create a file q.sh to run the application in development mode but in the background i.e:
    #!/bin/sh
    bin/rails s &
  2. Execute the script
    % chmod +x ./q.sh
    % ./q.sh
    /var/www/bundler/ruby/3.3/gems/reline-0.5.3/lib/reline/ansi.rb:246:in `winsize': Operation not supported by device - <STDIN> (Errno::ENODEV)                    
        from /var/www/bundler/ruby/3.3/gems/reline-0.5.3/lib/reline/ansi.rb:246:in `get_screen_size'
        from /var/www/bundler/ruby/3.3/gems/reline-0.5.3/lib/reline/line_editor.rb:78:in `initialize'                              
        from /var/www/bundler/ruby/3.3/gems/reline-0.5.3/lib/reline.rb:542:in `new'  
        from /var/www/bundler/ruby/3.3/gems/reline-0.5.3/lib/reline.rb:542:in `block in core'                                                                   
        from /var/www/bundler/ruby/3.3/gems/reline-0.5.3/lib/reline.rb:80:in `initialize'   

Checking the source code of reline 0.5.3 in lib/reline/ansi.rb function get_screen_size I notice that you handle only the exception Errno::ENOTTY:

  def self.get_screen_size                                                                                                                                      
    s = @@input.winsize                                                                                                                                         
    return s if s[0] > 0 && s[1] > 0                                                                                                                            
    s = [ENV["LINES"].to_i, ENV["COLUMNS"].to_i]                                                                                                                
    return s if s[0] > 0 && s[1] > 0                                                                                                                            
    [24, 80]                                                                                                                                                    
  rescue Errno::ENOTTY                                                                                                                                          
    [24, 80]                                                                                                                                                    
  end    

IMHO it is the same problem described by @revolter and @forthrin in #537.

It has worked for me to add support for the Errno::ENODEV exception i.e changing

  rescue Errno::ENOTTY

for

  rescue Errno::ENOTTY, Errno::ENODEV

Terminal Emulator

tmux on xterm on OpenBSD/adJ 7.4

@forthrin
Copy link

@vtamara: WFM

  rescue Errno::ENOTTY, Errno::ENODEV
$ echo Foo | xargs ruby -r readline -e "puts 'Bar'"
Bar

When will this make it into the official Rubygems distribution?

@ima1zumi ima1zumi added the bug Something isn't working label Apr 29, 2024
@onemanteamsoftware
Copy link

winsize appears to be causing problems on windows 10 too, at least since the v0.5.0 release. Running bin/dev in a rails project results in:

> $ bin/dev
C:/ProgramData/Ruby32-x64/lib/ruby/gems/3.2.0/gems/reline-0.5.4/lib/reline/ansi.rb:246:in `winsize': Bad file descriptor - <STDIN> (Errno::EBADF)

vtamara added a commit to vtamara/reline that referenced this issue May 10, 2024
@tompng tompng closed this as completed in a5b5298 May 22, 2024
matzbot pushed a commit to ruby/ruby that referenced this issue May 22, 2024
get_screen_size. Closes ruby/reline#690
(ruby/reline#702)

* Catches exceptions Errno::ENODEV and Errno::EBADF in get_screen_size. Closes ruby/reline#690

* Just catching Errno::ENOTTY and Errno::ENODEV

ruby/reline@a5b5298e4a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

4 participants