mattbrictson / airbrussh

Airbrussh pretties up your SSHKit and Capistrano output

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JRuby NoMethodError: undefined method `open?' for #<File:/dev/tty>

adamdilek opened this issue · comments

I'm getting this error in JRuby

cap aborted!
NoMethodError: undefined method `open?' for #<File:/dev/tty>
/usr/local/rbenv/versions/jruby-9.0.0.0/lib/ruby/stdlib/io/console.rb:159:in `console'
/usr/local/rbenv/versions/jruby-9.0.0.0/lib/ruby/gems/shared/gems/airbrussh-0.5.1/lib/airbrussh/console.rb:59:in `console_width'
/usr/local/rbenv/versions/jruby-9.0.0.0/lib/ruby/gems/shared/gems/airbrussh-0.5.1/lib/airbrussh/console.rb:42:in `truncate_to_console_width'
/usr/local/rbenv/versions/jruby-9.0.0.0/lib/ruby/gems/shared/gems/airbrussh-0.5.1/lib/airbrussh/console.rb:26:in `print_line'
/usr/local/rbenv/versions/jruby-9.0.0.0/lib/ruby/gems/shared/gems/airbrussh-0.5.1/lib/airbrussh/formatter.rb:174:in `print_line'
/usr/local/rbenv/versions/jruby-9.0.0.0/lib/ruby/gems/shared/gems/airbrussh-0.5.1/lib/airbrussh/formatter.rb:42:in `write_banner'
/usr/local/rbenv/versions/jruby-9.0.0.0/lib/ruby/gems/shared/gems/airbrussh-0.5.1/lib/airbrussh/formatter.rb:28:in `initialize'
/usr/local/rbenv/versions/jruby-9.0.0.0/lib/ruby/gems/shared/gems/sshkit-1.7.1/lib/sshkit/configuration.rb:48:in `block in formatter'

Thanks for the report. For now, you can probably work around this by disabling auto-truncation. Try putting this code in your deploy.rb:

Airbrussh.configure do |config|
  config.truncate = false
end

I've confirmed this is a bug in jruby: the IO.console.winsize method doesn't work.

>> require "io/console"
false
>> IO.console
#<File:/dev/tty>
crw-rw-rw-  1 root  wheel    2,   0 Sep 19 09:11 /dev/tty
>> IO.console.winsize
NoMethodError: undefined method `open?' for #<File:/dev/tty>
    from /Users/mbrictson/.rbenv/versions/jruby-9.0.0.0/lib/ruby/stdlib/io/console.rb:159:in `console'
    from (irb):3:in `<eval>'
    from org/jruby/RubyKernel.java:979:in `eval'
    from org/jruby/RubyKernel.java:1292:in `loop'
    from org/jruby/RubyKernel.java:1099:in `catch'
    from org/jruby/RubyKernel.java:1099:in `catch'
    from /Users/mbrictson/.rbenv/versions/jruby-9.0.0.0/bin/irb:13:in `<top>'

@muhammett can you open a bug report in https://github.com/jruby/jruby ?

Thank you @mattbrictson . I report to jruby jruby/jruby#3340

This is apparently fixed in the next release of JRuby 9.x. I've also added a JRuby compatibility note to the Airbrussh README in ce927be. Closing.

@mattbrictson IO.console could be also nil if Ruby executable is called through a sudo su - user -c '~/.rvm/bin/rvm 2.3.1 do ruby -e -e "require %{io/console}; puts IO.console.winsize"' construction. It should be nil-checked anyway.

(To be honest, in this case @output.tty? should not be true, I think it's a bug in ruby, but should be workarounded.

$  sudo su - app -c 'cd /deploy/ && /home/app/.rvm/bin/rvm ruby-2.3.1@default do ruby -e "require %{io/console}; puts IO.console.winsize"'
-e:1:in `<main>': undefined method `winsize' for nil:NilClass (NoMethodError)

$ /home/app/.rvm/bin/rvm ruby-2.3.1@default do ruby -e "require %{io/console}; puts IO.console.winsize"
55
211
$ 

IO.console could be also nil

@hron84 Thanks for pointing that out! Can you open a new Airbrussh issue for the nil problem? It is not related to JRuby so it should be logged as a separate issue.