4

我最近安装了 gem pry-byebug,当我注意到它至少需要 Ruby 2.4 版才能运行时。所以我使用 更新了我的 Ruby rvm,然后安装了 gemsprypry-byebug. 一切正常。我开始编写一些代码并设置一些断点binding.pry

但是现在当我调试时,我必须处理来自pry-byebug.我的问题在哪里。

例如,假设我binding.pry在实例化一些对象的部分代码中设置了一个断点。

casting1= {'movie_name'=> 'The Room, 'star_name'=> 'Tommy Wiseau', 'star_fee'=>20000}
casting2= {'movie_name'=> 'Come and See', 'star_name'=> 'Aleksei Kravchenko', 'star_fee'=>1000}
casting_object1= Casting.new(casting1)
casting_object2= Casting.new(casting2)

binding.pry()

假设我开始查看对象casting_object1casting_object2确定它们的方法是否已正确编写,并且我不小心输入了一些小错误,例如调用不存在的对象/函数。我得到这种输出:

[1] pry(main)> casting_object1
[2] pry(main)> casting_object5

Traceback (most recent call last):
        27: from console.rb:64:in `<main>'
        26: from /Users/bob/.rvm/gems/ruby-head/gems/byebug-11.1.1/lib/byebug/context.rb:98:in `at_line'
        25: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:65:in `at_line'
        24: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:113:in `resume_pry'
        23: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:29:in `run'
        22: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:29:in `catch'
        21: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:30:in `block in run'
        20: from /Users/bob/.rvm/gems/ruby-head/gems/byebug-11.1.1/lib/byebug/helpers/eval.rb:94:in `allowing_other_threads'
        19: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:30:in `block (2 levels) in run'
        18: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:117:in `block in resume_pry'
        17: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_class.rb:200:in `start'
        16: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:13:in `start'
        15: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:38:in `start'
        14: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/input_lock.rb:77:in `with_ownership'
        13: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/input_lock.rb:59:in `__with_ownership'
        12: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:38:in `block in start'
        11: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:67:in `repl'
        10: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:67:in `loop'
         9: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:77:in `block in repl'
         8: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:272:in `eval'
         7: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:272:in `catch'
         6: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:273:in `block in eval'
         5: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:273:in `catch'
         4: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:274:in `block (2 levels) in eval'
         3: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:355:in `handle_line'
         2: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:387:in `evaluate_ruby'
         1: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:387:in `eval'
(pry):3:in `<main>': undefined local variable or method `casting' for main:Object (NameError)
Did you mean?  casting_object2
               casting_object1
        27: from console.rb:64:in `<main>'
        26: from /Users/bob/.rvm/gems/ruby-head/gems/byebug-11.1.1/lib/byebug/context.rb:98:in `at_line'
        25: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:65:in `at_line'
        24: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:113:in `resume_pry'
        23: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:29:in `run'
        22: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:29:in `catch'
        21: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:30:in `block in run'
        20: from /Users/bob/.rvm/gems/ruby-head/gems/byebug-11.1.1/lib/byebug/helpers/eval.rb:94:in `allowing_other_threads'
        19: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:30:in `block (2 levels) in run'
        18: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:117:in `block in resume_pry'
        17: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_class.rb:200:in `start'
        16: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:13:in `start'
        15: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:38:in `start'
        14: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/input_lock.rb:77:in `with_ownership'
        13: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/input_lock.rb:59:in `__with_ownership'
        12: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:38:in `block in start'
        11: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:67:in `repl'
        10: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:67:in `loop'
         9: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/repl.rb:77:in `block in repl'
         8: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:272:in `eval'
         7: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:272:in `catch'
         6: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:273:in `block in eval'
         5: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:273:in `catch'
         4: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:274:in `block (2 levels) in eval'
         3: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:349:in `handle_line'
         2: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_instance.rb:356:in `rescue in handle_line'
         1: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/exceptions.rb:16:in `==='
/Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/exceptions.rb:28:in `===': undefined method `>' for nil:NilClass (NoMethodError)
        12: from console.rb:64:in `<main>'
        11: from /Users/bob/.rvm/gems/ruby-head/gems/byebug-11.1.1/lib/byebug/context.rb:98:in `at_line'
        10: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:65:in `at_line'
         9: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:113:in `resume_pry'
         8: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:29:in `run'
         7: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:29:in `catch'
         6: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:30:in `block in run'
         5: from /Users/bob/.rvm/gems/ruby-head/gems/byebug-11.1.1/lib/byebug/helpers/eval.rb:94:in `allowing_other_threads'
         4: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:30:in `block (2 levels) in run'
         3: from /Users/bob/.rvm/gems/ruby-head/gems/pry-byebug-3.8.0/lib/byebug/processors/pry_processor.rb:117:in `block in resume_pry'
         2: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_class.rb:169:in `start'
         1: from /Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/pry_class.rb:201:in `rescue in start'
/Users/bob/.rvm/gems/ruby-head/gems/pry-0.12.2/lib/pry/exceptions.rb:28:in `===': undefined method `>' for nil:NilClass (NoMethodError)

无论引发什么样的错误,我总是会得到这种似乎是在引用pryor pry-byebuggem 的代码库中的代码的输出。虽然这不是一个主要问题(因为我仍然可以设置断点并在 pry 中操作对象),但有太多多余的输出,以至于查明错误的过程变得不是特别容易或明确,尤其是在终端设置中。我自己尝试通过卸载并重新安装 gemspry和来修正这个问题pry-byebug,并且还尝试安装以前版本的pryandpry-byebug以使其正常工作。我试图用谷歌搜索这个问题,但遗憾的是,我对术语不够熟悉,无法确定问题的实质。

自从我用 rvm 更新了我的 Ruby,这个问题就一直在发生。我不想回到旧版本的 Ruby,因为我在代码中使用的一些 gem 需要最新版本。任何人都可以给我任何反馈来解释为什么会发生这种情况,并且可能,我该如何解决它?我正在使用 macOS Mojave v10.14.6,并使用 Ruby v2.7.0-preview1

更新

于是我去了 的 github 仓库,pry-byebug发现其他一些用户也遇到了和我一样的问题。

https://github.com/deivid-rodriguez/pry-byebug/issues/138

https://github.com/deivid-rodriguez/pry-byebug/issues/110

可悲的是,这两个问题仍未解决,但一位用户确实表示有一种方法可以使用该功能“猴子补丁”问题print_traceback。在 gem 的文件中定位到print_traceback函数后,我尝试实现这个猴子补丁。可悲的是,它对我不起作用。 where.rbbye-bug

4

3 回答 3

1

所以我最近刚刚使用 rvm 下载并将我的默认 Ruby 版本设置为 2.6.5。详细输出现已完全停止。

于 2020-03-11T22:10:07.223 回答
0

它不仅是错误的完整回溯,而且是捕获错误的代码的完整回溯。只需跟踪即可。如果你不喜欢冗长的输出然后发送 PR,不要猴子补丁。如果 gem 得到更新,那么如果您想保持更新,那么您的补丁将毫无用处。

于 2020-03-08T21:49:57.037 回答
0

我认为您可以降级到 pry-byebug-3.6.0,它可能会解决问题。我使用的是 3.6.0,打印完整的回溯没有问题。

于 2020-03-10T03:21:26.433 回答