Skip to content

Commit

Permalink
Merge pull request airbrake#12 from leonid-shevtsov/master
Browse files Browse the repository at this point in the history
Fixed: rake handler failing when exception happens before Airbrake has been configured
  • Loading branch information
usiegj00 committed Oct 9, 2011
2 parents 172370d + 9237cf4 commit 64464ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions features/rake.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions features/support/rake/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,24 @@ 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
$stderr.puts "airbrake #{args[1][:component]}"
end
end

def stub_empty_sender
Airbrake.sender = nil
end

def stub_tty_output(value)
Rake.application.instance_eval do
@tty_output_stub = value
Expand Down
4 changes: 2 additions & 2 deletions lib/airbrake/rake_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 64464ed

Please sign in to comment.