我在Ruby 1.9.3上使用Ruby on Rails 4。當在rake任務中發生錯誤時,我會得到一個非常好的堆棧跟蹤。在Rails 4控制檯中啓用堆棧轉儲異常
但是,當我在我的rails控制檯(pry)中做了一些觸發異常的事情時,我只能看到錯誤消息和觸發它的一行代碼(大部分時間都在rails core中)。
有沒有辦法在控制檯中啓用這些堆棧轉儲?
我在Ruby 1.9.3上使用Ruby on Rails 4。當在rake任務中發生錯誤時,我會得到一個非常好的堆棧跟蹤。在Rails 4控制檯中啓用堆棧轉儲異常
但是,當我在我的rails控制檯(pry)中做了一些觸發異常的事情時,我只能看到錯誤消息和觸發它的一行代碼(大部分時間都在rails core中)。
有沒有辦法在控制檯中啓用這些堆棧轉儲?
我找到了解決自己。
顯然,我需要撬撥的命令wtf?
。
[7] project » p.known_attributes
NoMethodError: undefined method `foo' for #<Bar:0x007f871fd12a38>
from /[...]/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:436:in `method_missing'
[8] project » wtf?
Exception: NoMethodError: undefined method `foo' for #<Bar:0x007f871fd12a38>
--
[... stack dump ...]
[9] project »
當有在控制檯的錯誤,你應該看到這樣的事情
$ rails c
Loading development environment (Rails 4.0.0)
irb(main):001:0> no_method
NameError: undefined local variable or method `no_method' for main:Object
from (irb):1
from /Users/michal/Projects/tennisliga/.gems/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /Users/michal/Projects/tennisliga/.gems/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /Users/michal/Projects/tennisliga/.gems/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
出了什麼問題呢?你沒有看到堆棧跟蹤?
編輯: 如果您在使用撬,並希望看到更多的堆棧跟蹤,請參閱pry wiki 簡單的例子(顯示所有行)
Pry.config.exception_handler = proc do |output, exception, _pry_|
output.puts "#{exception}"
output.puts "#{exception.backtrace}"
end
當我做到這些,有什麼我得到的只是'NameError:未定義的局部變量或方法「no_method」主:對象 從(撬):1:在「
我剛纔看到撬可能在這裏有一隻手。這可能嗎? –
你有沒有設置爲默認控制檯? –
這讓我開心 –