LoginSignup
1
1

More than 5 years have passed since last update.

EventMachineのイベントハンドラでエラーが発生したときにバックトレースを表示する

Last updated at Posted at 2017-01-25

faye-websocketを使ったコードを書いているときに、on(:message)とかのイベントハンドラでエラーがあっても何も表示されないのでかなりあせりました。
faye-websocketが非同期処理に使っているEventMachineがそもそもそういう動作っぽいです。

開発中は以下のようなコードをファイルの先頭あたりにでもいれておけばイベントハンドラ内でのエラーが表示されるようになって幸福実現です。

EM.error_handler{ |e|
  STDERR.puts e.message
  STDERR.puts e.backtrace.join("\n")
}

参考: http://stackoverflow.com/questions/7628232/how-to-catch-top-level-failures-on-an-eventmachine-server

1
1
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
1