Skip to content

Catches Errno::ENODEV and Errno::EBADF in get_screen_size. Closes #690 - #702

Merged
tompng merged 2 commits into
ruby:masterfrom
vtamara:fix690
May 22, 2024
Merged

tompng merged 2 commits into
ruby:masterfrom
vtamara:fix690

Conversation

@vtamara

@vtamara vtamara commented May 10, 2024

Copy link
Copy Markdown
Contributor

No description provided.

@tompng

tompng commented May 10, 2024

Copy link
Copy Markdown
Member

Additional information how to reproduce these Errno

Errno::ENOTTY

echo | ruby -rio/console -e "STDIN.winsize"

Errno::ENODEV

ruby -rio/console -e "STDIN.winsize" < /dev/null

Errno::EBADF

ruby -rio/console -e "io=IO.popen('cat','r+'); fd=io.inspect[/\d+/].to_i; io2=IO.for_fd(fd); io.close; io2.winsize"

(Haven't found a way to raise EBADF from STDIN.winsize)

Comment thread lib/reline/ansi.rb Outdated
return s if s[0] > 0 && s[1] > 0
[24, 80]
rescue Errno::ENOTTY
rescue Errno::ENOTTY, Errno::ENODEV, Errno::EBADF

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding Errno::ENODEV is enough.

The main problem of #690 is that just requiring 'reline' was calling IO#winsize. #703 will fix it.

We need to rescue Errno::ENOTTY and Errno::ENODEV to make reline work in these two scenario.

# For Errno::ENODEV
ruby -rreline -e "Reline.readline" < /dev/null
# For Errno::ENOTTY
ruby -rreline -e "Reline.readline" < file

But for Errno::EBADF, I think we don't need to rescue it. Just like we don't rescue IOError here.

STDIN.close
STDIN.winsize #=> closed stream (IOError)
Reline.readline #=> `tty?': closed stream (IOError)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, just catching Errno::ENOTTY and Errno::ENODEV

@tompng tompng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

@tompng
tompng merged commit a5b5298 into ruby:master May 22, 2024
matzbot pushed a commit to ruby/ruby that referenced this pull request 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
@vtamara
vtamara deleted the fix690 branch May 22, 2024 19:17
@vtamara

vtamara commented May 22, 2024

Copy link
Copy Markdown
Contributor Author

Thank you 👍

Welcome. Thank you.

@ima1zumi ima1zumi added the bug Something isn't working label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants