From b4e6291ca7ea309d5c4acabc92fb49a27b9b0c50 Mon Sep 17 00:00:00 2001 From: Lee Henson Date: Mon, 7 Oct 2013 14:44:31 +0100 Subject: [PATCH] don't fail when handling an exception with a nil backtrace --- lib/sidekiq/exception_handler.rb | 2 +- test/test_exception_handler.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/sidekiq/exception_handler.rb b/lib/sidekiq/exception_handler.rb index acf7e363..cec11277 100644 --- a/lib/sidekiq/exception_handler.rb +++ b/lib/sidekiq/exception_handler.rb @@ -4,7 +4,7 @@ module Sidekiq def handle_exception(ex, ctxHash={}) Sidekiq.logger.warn(ctxHash) if !ctxHash.empty? Sidekiq.logger.warn ex - Sidekiq.logger.warn ex.backtrace.join("\n") + Sidekiq.logger.warn ex.backtrace.join("\n") unless ex.backtrace.nil? # This list of services is getting a bit ridiculous. # For future error services, please add your own # middleware like BugSnag does: diff --git a/test/test_exception_handler.rb b/test/test_exception_handler.rb index d333291c..43bd388a 100644 --- a/test/test_exception_handler.rb +++ b/test/test_exception_handler.rb @@ -37,6 +37,20 @@ class TestExceptionHandler < Sidekiq::Test assert_match /Something didn't work!/, log[1], "didn't include the exception message" assert_match /test\/test_exception_handler.rb/, log[2], "didn't include the backtrace" end + + describe "when the exception does not have a backtrace" do + it "does not fail" do + exception = ExceptionHandlerTestException.new + assert_nil exception.backtrace + + begin + Component.new.handle_exception exception + pass + rescue => e + flunk "failed handling a nil backtrace" + end + end + end end describe "with fake Airbrake" do