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

问题描述 投票:9回答:2

在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)

知道问题是什么吗?

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

ruby pry
2个回答
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)

然后我尝试按照pry.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

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

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.