输入无效命令时,rails 控制台中的额外行项目是什么?

What are the extra line items in rails console when entering an invalid command?

具体来说,我看到:

Loading development environment (Rails 4.2.1)
irb(main):001:0> f
NameError: undefined local variable or method `f' for main:Object
from (irb):1
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:110:in `start'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:9:in `start'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
from /Users/benjamin/demo/bin/rails:8:in `<top (required)>'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/commands/rails.rb:6:in `call'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/command_wrapper.rb:38:in `call'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:183:in `block in serve'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:156:in `fork'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:156:in `serve'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:131:in `block in run'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:125:in `loop'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:125:in `run'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

我怎样才能永久隐藏这些并只看到实际的错误消息?我在网上发现了一些展示如何暂时隐藏这些行项目的东西,包括:

IRB.CurrentContext.back_trace_limit = 0

但还没有永久性的东西。

感谢您的帮助!

额外的行是您从当前上下文调用中正确识别的 "backtrace"。

我认为您需要按照 here 所述添加 .irbrc 文件。这通常位于您的主目录中,但如果主目录不包含该文件,它将使用当前目录中的 .irbrc 文件。

在该文件中,您可以在每次调用 irbrails console:

时添加一行来限制回溯的大小
IRB.conf[:BACK_TRACE_LIMIT] = 0

您可能不想将它减少到零,因为如果错误消息本身不是特别有用,它有时会提供有关错误可能源自何处的线索。