5

这个问题是间歇性的,但是按向上箭头来获取以前输入的命令我会得到一个错误,例如:

/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>'

看起来问题出在readline中?如何解决问题?根据bundle list我有这个版本的readline:

  • rb-readline (0.4.2)

更新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>'

而且我仍然遇到旧错误。

4

2 回答 2

4

这显然是 rb-readline 的问题。

我通常将 readline 安装为 rvm 包:

rvm pkg install readline

并且不要在我的 Gemfile 中使用任何 readline 特定的东西。

你也可以看看:

rails 控制台、RVM 和 readline 的问题

于 2013-01-22T22:13:26.850 回答
0

我今天遇到了这个。

我相信这是因为 readline 试图解析控制台行上的一些文本。有些文字播放不好。

那么为什么是向上键呢?

这恰好是在我粘贴大量“东西”来设置变量之后。由于控制台崩溃了,我显然在粘贴中出了点问题。

发生崩溃后,所有 IT 专业人员都会做什么?再试一遍。尝试您在 rails 控制台中编写的最后一个命令的最快方法是什么?向上键。

一个很好的解决方法是简单地不按向上键或清除历史记录以删除有问题的行。

于 2016-09-02T09:47:12.357 回答