before_session hook失败:Pry :: CommandError:无法找到此方法:load

时间:2013-05-23 18:34:08

标签: ruby pry

在Ruby脚本中加载Pry REPL我得到了这个奇怪的错误:

before_session hook failed: Pry::CommandError: Cannot locate this method: load.
~/.rvm/gems/ruby-2.0.0-p195/gems/pry-0.9.12.2/lib/pry/method.rb:498:in `pry_doc_info'
(see _pry_.hooks.errors to debug)

知道问题是什么吗?

注意: 代码似乎执行得很好,除了那个神秘的消息和 2.我找不到“_pry_.hooks.errors”文件

2 个答案:

答案 0 :(得分:1)

我在Gemfile中使用Ruby 2.4.1和Pry Stack Explorer遇到了这个问题,

gem 'pry'
gem 'pry-rescue'
gem 'pry-stack_explorer'

在插入Pry调试器时,我看到:

before_session hook failed: Pry::CommandError: Cannot locate this method: load. Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.
/Users/alexharvey/.rvm/gems/ruby-2.4.1/gems/pry-0.11.3/lib/pry/method.rb:489:in `pry_doc_info'
(see _pry_.hooks.errors to debug)

然后我尝试按照有关 .hooks.errors的说明进行操作:

[2] pry(#<MarkdownLint::Rule>)> puts _pry_.hooks.errors
Cannot locate this method: load. Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.
=> nil

所以我刚刚在我的Gemfile中添加了pry-doc。然后,我还有另一个问题。在尝试退出调试器时:

[2] pry(#<MarkdownLint::Rule>)>
when_started hook failed: NameError: uninitialized constant RubyVM::DebugInspector
/Users/alexharvey/.rvm/gems/ruby-2.4.1/gems/binding_of_caller-0.8.0/lib/binding_of_caller/mri2.rb:21:in `callers'
(see _pry_.hooks.errors to debug)

我发现我可以通过不请求最新版本的debug_inspector来解决该问题。

最后,要成功使用pry和pry-stack_explorer,我最终得到:

gem 'pry'
gem 'pry-rescue'
gem 'pry-stack_explorer'
gem 'pry-doc'
gem 'debug_inspector', '<= 0.0.2'

答案 1 :(得分:0)

从源代码看起来钩子可能引发异常,但随后吞下它。上面的评论exec_hook建议您查询$pry_hook_error以了解发生的情况。

# Execute the specified hook.
# @param [Symbol] name The hook name to execute
# @param [*Object] args The arguments to pass to the hook
# @return [Object, Exception] The return value of the hook or the exception raised
#
# If executing a hook raises an exception, we log that and then continue sucessfully.
# To debug such errors, use the global variable $pry_hook_error, which is set as a
# result.
def exec_hook(name, *args, &block)
  e_before = hooks.errors.size
  hooks.exec_hook(name, *args, &block).tap do
    hooks.errors[e_before..-1].each do |e|
      output.puts "#{name} hook failed: #{e.class}: #{e.message}"
      output.puts "#{e.backtrace.first}"
      output.puts "(see _pry_.hooks.errors to debug)"
    end
  end
end

我无法复制这个,所以请原谅我,如果这是非常偏离基础。