Skip to content

Commit

Permalink
airbrake-ruby: ignore SystemExit in the at_exit hook
Browse files Browse the repository at this point in the history
Fixes #13 (Unnecessary airbrake error when running unknown rake task)

The problem with Rake is that on unknown task it
[raises SystemExit][1] with help of [`Kernel.exit`][2], which we catch
and try to send to Airbrake, which results in an Airbrake::Error.

This is the easiest fix. I tried messing with the airbrake gem to load
the Airbrake config when you launch a Rake task inside a Rails app, but
it's not easy to do: the Rails app is not initialised at that moment.

I stopped digging there, because I was getting into the rabbit hole.

[1]: https://github.com/ruby/rake/blob/805c13ab52eae9df55f9030f40c7fbc1beadc105/lib/rake/application.rb#L191
[2]: http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-exit
  • Loading branch information
kyrylo committed Dec 25, 2015
1 parent 2702945 commit 7fb4931
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Airbrake Ruby Changelog

### master

* Ignored `SystemExit` in the `at_exit` hook, which has fixed the Rake
integration for the [airbrake gem][airbrake] gem
([#14](https://github.com/airbrake/airbrake-ruby/pull/14))

### [v1.0.1][v1.0.1] (December 22, 2015)

* Fixed the `Airbrake.add_filter` block API
Expand All @@ -17,6 +21,7 @@ Airbrake Ruby Changelog

* Initial release

[airbrake-gem]: https://github.com/airbrake/airbrake
[v1.0.0.rc.1]: https://github.com/airbrake/airbrake-ruby/releases/tag/v1.0.0.rc.1
[v1.0.0]: https://github.com/airbrake/airbrake-ruby/releases/tag/v1.0.0
[v1.0.1]: https://github.com/airbrake/airbrake-ruby/releases/tag/v1.0.1
6 changes: 4 additions & 2 deletions lib/airbrake-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ def call_notifier(notifier, method, *args, &block)
end
end

# Notify of unhandled exceptions, if there were any.
# Notify of unhandled exceptions, if there were any, but ignore SystemExit.
at_exit do
Airbrake.notify_sync($ERROR_INFO) if $ERROR_INFO
if $ERROR_INFO && $ERROR_INFO.class != SystemExit
Airbrake.notify_sync($ERROR_INFO)
end
end

0 comments on commit 7fb4931

Please sign in to comment.