From ea786113acb3e1fb1a57d21934f300f2c9f9d78c Mon Sep 17 00:00:00 2001 From: Marius Hanne Date: Thu, 17 Mar 2016 04:43:21 +0100 Subject: [PATCH] handle command errors this prevents the whole bot from crashing when one commad raises an exception --- lib/jabber/bot.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/jabber/bot.rb b/lib/jabber/bot.rb index 93c9805..01e9993 100644 --- a/lib/jabber/bot.rb +++ b/lib/jabber/bot.rb @@ -378,8 +378,14 @@ def parse_command(sender, message) #:nodoc: params = match.captures # Pass an array, params = params.pop if params.count < 2 # a string, or nil. - response = command[:callback].call(sender, params) - deliver(sender, response) unless response.nil? + begin + response = command[:callback].call(sender, params) + deliver(sender, response) unless response.nil? + rescue Exception + p $! + puts *$@ + deliver(sender, "ERROR: #{$!}") + end return end