Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed rake handler failing when exception happens before Airbrake has…

… been configured (for example, when running an unknown Rake task)
  • Loading branch information...
commit 9237cf49b6739c3a77560a5d21dd5d24a1d43642 1 parent 5758fc5
@leonid-shevtsov authored
View
4 features/rake.feature
@@ -6,6 +6,10 @@ Feature: Use the Gem to catch errors in a Rake application
When I run rake with airbrake
Then Airbrake should catch the exception
+ Scenario: Falling back to default handler before Airbrake is configured
+ When I run rake with airbrake not yet configured
+ Then Airbrake should not catch the exception
+
Scenario: Disabling Rake exception catcher
When I run rake with airbrake disabled
Then Airbrake should not catch the exception
View
11 features/support/rake/Rakefile
@@ -36,6 +36,13 @@ task :airbrake_autodetect_not_from_terminal do
raise_exception
end
+task :airbrake_not_yet_configured do
+ Airbrake.configuration.rescue_rake_exceptions = true
+ stub_tty_output(true)
+ stub_empty_sender
+ raise_exception
+end
+
module Airbrake
def self.notify(*args)
# TODO if you need to check more params, you'll have to use json.dump or something
@@ -43,6 +50,10 @@ module Airbrake
end
end
+def stub_empty_sender
+ Airbrake.sender = nil
+end
+
def stub_tty_output(value)
Rake.application.instance_eval do
@tty_output_stub = value
View
4 lib/airbrake/rake_handler.rb
@@ -9,8 +9,8 @@ def self.included(klass)
end
def display_error_message_with_airbrake(ex)
- if Airbrake.configuration.rescue_rake_exceptions ||
- (Airbrake.configuration.rescue_rake_exceptions===nil && !self.tty_output?)
+ if Airbrake.sender && (Airbrake.configuration.rescue_rake_exceptions ||
+ (Airbrake.configuration.rescue_rake_exceptions===nil && !self.tty_output?))
Airbrake.notify(ex, :component => reconstruct_command_line, :cgi_data => ENV)
end
Please sign in to comment.
Something went wrong with that request. Please try again.