简体   繁体   English

由于readline中的错误,我按下按钮时Rails脚本/控制台崩溃

[英]Rails script/console crashes when I press up button because of bug in readline

This issue is intermittent, but pressing the up-arrow to get a previously entered command I'll get an error such as: 此问题是间歇性的,但按向上箭头以获取先前输入的命令我将收到错误,例如:

/Users/me/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-2.3.14/lib/active_support/whiny_nil.rb:52:in `method_missing': undefined method `force_encoding' for nil:NilClass (NoMethodError)
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:3801:in `_rl_col_width'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:2944:in `update_line'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:3486:in `block in rl_redisplay'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:3481:in `each'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:3481:in `rl_redisplay'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:4618:in `_rl_internal_char_cleanup'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:4679:in `readline_internal_charloop'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:4743:in `readline_internal'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:4765:in `readline'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/readline.rb:40:in `readline'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/input-method.rb:115:in `gets'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:139:in `block (2 levels) in eval_input'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:138:in `block in eval_input'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `call'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `buf_input'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:103:in `getc'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/slex.rb:205:in `match_io'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:286:in `token'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:262:in `lex'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:233:in `block (2 levels) in each_top_level_statement'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:70:in `block in start'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:69:in `catch'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:69:in `start'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'

Looks like the issue is in readline? 看起来问题是在readline中? How to resolve the issue? 如何解决这个问题? According to bundle list I have this version of readline: 根据bundle list我有这个版本的readline:

  • rb-readline (0.4.2) rb-readline(0.4.2)

Update : New error after updating with rvm pkg install readline per answer: 更新 :使用rvm pkg install readline每个答案更新后出现新错误:

>/Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:2730:in `[]': no implicit conversion from nil to integer (TypeError)
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:2730:in `update_line'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:3486:in `block in rl_redisplay'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:3481:in `each'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:3481:in `rl_redisplay'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:4618:in `_rl_internal_char_cleanup'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:4679:in `readline_internal_charloop'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:4743:in `readline_internal'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/rbreadline.rb:4765:in `readline'
    from /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/rb-readline-0.4.2/lib/readline.rb:40:in `readline'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/input-method.rb:115:in `gets'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:139:in `block (2 levels) in eval_input'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:138:in `block in eval_input'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `call'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `buf_input'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:103:in `getc'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/slex.rb:205:in `match_io'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:286:in `token'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:262:in `lex'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:233:in `block (2 levels) in each_top_level_statement'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:70:in `block in start'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:69:in `catch'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:69:in `start'
    from /Users/me/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'

And I still get the old error, as well. 而且我仍然会得到旧的错误。

It's clearly a problem with rb-readline. 这显然是rb-readline的一个问题。

I usually install readline as an rvm package: 我通常将readline安装为rvm包:

rvm pkg install readline

And don't use any readline specific stuff in my Gemfile. 并且不要在我的Gemfile中使用任何readline特定的东西。

You may also have a look at: 你也可以看看:

Problems with the rails console, RVM and readline rails控制台,RVM和readline的问题

I encountered this today. 我今天遇到了这个。

I believe that this occurs because readline is trying to parse some of the text on the console line. 我相信这是因为readline试图解析控制台行上的一些文本。 Some text doesn't play nicely. 有些文字不能很好地发挥作用。

So why the up key? 那么为什么关键呢?

This happened to be after I pasted a load of 'stuff' to set a variable. 这恰好是在我粘贴了一堆'stuff'来设置变量之后。 I obviously got something wrong in that pasting because the console crashed. 我显然在粘贴中出了问题,因为控制台崩溃了。

What do all IT professionals do after something crashes? 在崩溃之后,所有IT专业人员都会做些什么? Try it again. 再试一遍。 Whats the quickest way to try the last command you wrote in the rails console? 什么是尝试在rails控制台中编写的最后一个命令的最快方法? The up key. 向上键。

A good work around for this is to simply not hit the up key or clear the history to remove the offending line. 一个很好的解决方法就是不要点击向上键或清除历史记录以删除违规行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM