Since version 5 Airbrake and its Rails integration offers automatic exception reporting in any Rake tasks. However I've not received rake exception on my errbit server.
I've made the following test :
Gemfile
source 'https://rubygems.org'
gem 'rails', '4.1.6'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'spring', group: :development
gem 'airbrake', '5.0.5'
initializers/airbrake.rb
Airbrake.configure do |config|
config.environment = Rails.env
config.host = 'https://xxxxxxxxxx.herokuapp.com/'
config.project_id = true
config.project_key = 'xxxxxxxxxxx'
config.ignore_environments = []
end
lib/rake/raise.rake
namespace :raise do
desc 'raise error'
task error: :environment do
1 / 0
end
end
I tried to execute the rake task rake raise:error
and got the following backtrace:
rake aborted!
ZeroDivisionError: divided by 0
/Users/Yann/code/airbraker/lib/tasks/raise.rake:4:in `/'
/Users/Yann/code/airbraker/lib/tasks/raise.rake:4:in `block (2 levels) in <top (required)>'
/Users/Yann/.gem/ruby/2.2.2/gems/airbrake-5.0.5/lib/airbrake/rake/task_ext.rb:19:in `execute'
Tasks: TOP => raise:error
(See full trace by running task with --trace)
And never received any exception on my errbit server.
Note: execute rake airbrake:test
sends an exception to my errbit server, I assume my configuration is correct.
Am I missing something ?
This is a minor bug. The problem is that Airbrake tries to be asynchronous and sometimes it doesn't work as expected. In this particular case the Ruby process quits before Airbrake sends your exception.
I've submitted a patch, which should fix this issue: https://github.com/airbrake/airbrake/pull/513