Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
Allow setting the ignore list off for exceptions on a per exception l…
Browse files Browse the repository at this point in the history
…evel.
  • Loading branch information
rsanheim committed Jan 4, 2010
1 parent 67ab18d commit 55f178e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.markdown
@@ -1,5 +1,9 @@
# Changelog

### 0.8.5
- Allow setting the ignore list off for exceptions on a per
exception level.

### 0.8.4
- Log ignored exceptions

Expand Down
19 changes: 19 additions & 0 deletions examples/lib/chatterbox/exception_notification_example.rb
Expand Up @@ -17,6 +17,12 @@
Chatterbox::ExceptionNotification.configure { |c| c.ignore = Chatterbox::ExceptionNotification.default_ignored_exceptions }
end

it "does not notify" do
Chatterbox::ExceptionNotification.configure { |c| c.ignore << RuntimeError }
Chatterbox.expects(:notify).never
Chatterbox::ExceptionNotification.handle(:exception => RuntimeError.new)
end

it "returns nil for explicit exception" do
Chatterbox::ExceptionNotification.configure { |c| c.ignore << RuntimeError }
Chatterbox::ExceptionNotification.handle(RuntimeError.new).should be_nil
Expand All @@ -32,9 +38,22 @@
Chatterbox.logger.expects(:debug).once
Chatterbox::ExceptionNotification.handle(RuntimeError.new)
end

describe "with the ignore list manually turned off" do
it "notifies" do
Chatterbox::ExceptionNotification.configure { |c| c.ignore << RuntimeError }
Chatterbox.expects(:notify)
Chatterbox::ExceptionNotification.handle(:exception => RuntimeError.new, :use_ignore_list => false)
end
end
end

describe "when not on ignore list" do
it "notifies" do
Chatterbox.expects(:notify)
Chatterbox::ExceptionNotification.handle(:exception => Exception.new)
end

it "logs nothing" do
Chatterbox.logger.expects(:debug).never
Chatterbox::ExceptionNotification.handle(:exception => Exception.new)
Expand Down
18 changes: 16 additions & 2 deletions lib/chatterbox/exception_notification.rb
Expand Up @@ -11,7 +11,7 @@ module ExceptionNotification
# * Objects are simply treated as a 'summary' message were an exception may not be necessary
def handle(args)
hsh = normalize_to_hash(args)
return if on_ignore_list?(hsh[:exception])
return if use_ignore_list?(hsh) && on_ignore_list?(hsh[:exception])
hsh = Extracter.wrap(hsh)
hsh = RailsExtracter.wrap(hsh)
hsh = Presenter.render(hsh)
Expand All @@ -26,6 +26,14 @@ def normalize_to_hash(args)
end
end

# Check to see if we should use ignore list for this exception -
# first use the value from the passed in options, otherwise
# use the configuration value (which defaults to true)
def use_ignore_list?(hsh)
return hsh[:use_ignore_list] if hsh.key?(:use_ignore_list)
configuration.use_ignore_list
end

def on_ignore_list?(exception)
ignored = configuration.ignore.include?(exception.class) ||
configuration.ignore.include?(exception.class.to_s)
Expand All @@ -37,8 +45,14 @@ def log_ignored_exception(exception)
Chatterbox.logger.debug { %[Chatterbox::ExceptionNotification ignoring exception: "#{exception}" as its on the ignore list] }
end

# Default configuration for ExceptionNotification
# :ignore => array of exceptions to ignore by default
# :use_ignore_list => whether to use the ignore list -
# defaults to true, and can be overidden on per exception level
def configuration
@configuration ||= OpenStruct.new(:ignore => default_ignored_exceptions)
@configuration ||= OpenStruct.new(
:ignore => default_ignored_exceptions,
:use_ignore_list => true)
end

# Configure ExceptionNotification
Expand Down

0 comments on commit 55f178e

Please sign in to comment.