当命令执行某些错误时,为什么我的 pry-byebug 包会给出这么多输出?
Why is my pry-byebug package giving so much output when a command executes some error?
我最近安装了 gem pry-byebug
,当时我注意到它至少需要 Ruby 版本 2.4 才能运行。所以我使用 rvm
更新了我的 Ruby,然后安装了 gems pry
和 pry-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_object1
和 casting_object2
以确定它们的方法是否已正确编写,并且我不小心输入了一些小错误,例如调用object/function 不存在。我得到这种输出:
[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)
无论引发何种错误,我总是得到这种似乎引用 pry
或 pry-byebug
gem 代码库中的代码的输出.虽然这不是主要问题(因为我仍然可以设置断点和操作 pry 中的对象),但有太多多余的输出以至于查明错误的过程变得不是特别容易或明确,特别是在终端设置中。我已尝试通过卸载并重新安装 gems pry
和 pry-byebug
来自行修正此问题,并且还尝试安装以前版本的 pry
和 pry-byebug
] 为了让它工作。我曾尝试用谷歌搜索这个问题,但遗憾的是我对术语不够熟悉,无法查明问题到底是什么。
自从我用 rvm 更新 Ruby 后,这个问题就一直出现。我不想回到旧版本的 Ruby,因为我在代码中使用的一些 gem 需要最新版本。任何人都可以给我任何反馈来解释为什么会发生这种情况,以及我如何解决它吗?我正在使用 macOS Mojave v10.14.6,并利用 Ruby v2.7.0-preview1
更新
所以我去了pry-byebug
的github仓库,发现其他一些用户遇到了和我一样的问题。
https://github.com/deivid-rodriguez/pry-byebug/issues/138
https://github.com/deivid-rodriguez/pry-byebug/issues/110
遗憾的是,这两个问题仍未解决,但一位用户确实表示有一种方法可以使用函数 print_traceback
"monkey patch" 解决问题。在 bye-bug
gem 的 where.rb
文件中找到 print_traceback
函数后,我尝试实现这个猴子补丁。遗憾的是它对我不起作用。
它不仅是错误的完整回溯,也是捕获错误的代码的完整回溯。跟着踪迹走就行了。如果你不喜欢冗长的输出然后发送一个 PR,不要猴子补丁。如果 gem 得到更新,那么如果你想保持更新,你的补丁就没用了。
我认为您可以降级到 pry-byebug-3.6.0,它可能会解决问题。
我使用的是 3.6.0,打印完整的回溯没有问题。
所以我最近只是使用 rvm 下载并将 Ruby 的默认版本设置为 2.6.5。详细输出现已完全停止。
我最近安装了 gem pry-byebug
,当时我注意到它至少需要 Ruby 版本 2.4 才能运行。所以我使用 rvm
更新了我的 Ruby,然后安装了 gems pry
和 pry-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_object1
和 casting_object2
以确定它们的方法是否已正确编写,并且我不小心输入了一些小错误,例如调用object/function 不存在。我得到这种输出:
[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)
无论引发何种错误,我总是得到这种似乎引用 pry
或 pry-byebug
gem 代码库中的代码的输出.虽然这不是主要问题(因为我仍然可以设置断点和操作 pry 中的对象),但有太多多余的输出以至于查明错误的过程变得不是特别容易或明确,特别是在终端设置中。我已尝试通过卸载并重新安装 gems pry
和 pry-byebug
来自行修正此问题,并且还尝试安装以前版本的 pry
和 pry-byebug
] 为了让它工作。我曾尝试用谷歌搜索这个问题,但遗憾的是我对术语不够熟悉,无法查明问题到底是什么。
自从我用 rvm 更新 Ruby 后,这个问题就一直出现。我不想回到旧版本的 Ruby,因为我在代码中使用的一些 gem 需要最新版本。任何人都可以给我任何反馈来解释为什么会发生这种情况,以及我如何解决它吗?我正在使用 macOS Mojave v10.14.6,并利用 Ruby v2.7.0-preview1
更新
所以我去了pry-byebug
的github仓库,发现其他一些用户遇到了和我一样的问题。
https://github.com/deivid-rodriguez/pry-byebug/issues/138
https://github.com/deivid-rodriguez/pry-byebug/issues/110
遗憾的是,这两个问题仍未解决,但一位用户确实表示有一种方法可以使用函数 print_traceback
"monkey patch" 解决问题。在 bye-bug
gem 的 where.rb
文件中找到 print_traceback
函数后,我尝试实现这个猴子补丁。遗憾的是它对我不起作用。
它不仅是错误的完整回溯,也是捕获错误的代码的完整回溯。跟着踪迹走就行了。如果你不喜欢冗长的输出然后发送一个 PR,不要猴子补丁。如果 gem 得到更新,那么如果你想保持更新,你的补丁就没用了。
我认为您可以降级到 pry-byebug-3.6.0,它可能会解决问题。 我使用的是 3.6.0,打印完整的回溯没有问题。
所以我最近只是使用 rvm 下载并将 Ruby 的默认版本设置为 2.6.5。详细输出现已完全停止。