LoginSignup
1
0

pry のエラーメッセージを短くする

Posted at

nokogiriを使った処理をしてるとエラーが出たときにオブジェクトのテキスト量が多すぎてデフォルトの設定だと肝心のエラーメッセージを確認するためにコンソールを大量に巻き戻らないといけない

Nokogiri::XML::Documentクラスのエラーでだけ表示を短くしたかったけど方法がわからなかったので例外全てを300文字以上表示しないように変えてみた。

.pryrc
Pry.config.exception_handler = proc do |output, exception, _|
  output.puts "#{exception.class}: #{exception.message.truncate(300)}"
  output.puts "from #{exception.backtrace.first}"
end

もっとシンプルな解決策がありそうだけど見つからなかったので当面はこれで我慢しよう。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0