From a801ba52258ccd096f88c983ce7c63347cfd1a75 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Mon, 18 Jan 2016 16:25:22 +0200 Subject: [PATCH] airbrake-ruby: reraise SystemExit instead of raising Airbrak::Error Fixes #28 ("Airbrake::Error: the 'default' notifier isn't configured" thrown after unsuccessful specs) This fixes issues with the Rake integration. There was a [similar issue][1] to a bug with the Rake integration reported a couple of weeks ago. The change presented here fixes both issues by reraising `SystemExit`, which propagates it and gets handled by Ruby. [1]: https://github.com/airbrake/airbrake-ruby/issues/13 --- CHANGELOG.md | 3 +++ lib/airbrake-ruby.rb | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac723153..0df93546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ Airbrake Ruby Changelog ([#21](https://github.com/airbrake/airbrake-ruby/pull/21)) * Made the asynchronous delivery mechanism more robust ([#26](https://github.com/airbrake/airbrake-ruby/pull/26)) +* Improved `SystemExit` handling by ignoring it on a different level, which + fixed issues with the Rake integration for the [airbrake gem][airbrake-gem] + gem ([#32](https://github.com/airbrake/airbrake-ruby/pull/32)) ### [v1.0.2][v1.0.2] (January 3, 2016) diff --git a/lib/airbrake-ruby.rb b/lib/airbrake-ruby.rb index abac9996..5081ff7d 100644 --- a/lib/airbrake-ruby.rb +++ b/lib/airbrake-ruby.rb @@ -280,6 +280,10 @@ def call_notifier(notifier, method, *args, &block) if @notifiers.key?(notifier) @notifiers[notifier].__send__(method, *args, &block) else + # If we raise SystemExit, the Ruby process can gracefully quit without + # the unwanted Airbrake::Error. + raise args.first if args.first.class == SystemExit + raise Airbrake::Error, "the '#{notifier}' notifier isn't configured" end @@ -289,7 +293,5 @@ def call_notifier(notifier, method, *args, &block) # Notify of unhandled exceptions, if there were any, but ignore SystemExit. at_exit do - if $ERROR_INFO && $ERROR_INFO.class != SystemExit - Airbrake.notify_sync($ERROR_INFO) - end + Airbrake.notify_sync($ERROR_INFO) if $ERROR_INFO end