Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ You can configure Solid Errors via the Rails configuration object, under the `so
* `email_subject_prefix` - Prefix added to the subject line for email notifications. See [Email notifications](#email-notifications) for more information.
* `base_controller_class` - Specify a different controller as the base class for the Solid Errors controller. See [Authentication](#authentication) for more information.
* `destroy_after` - If set, Solid Errors will periodically destroy resolved records that are older than the value specified. See [Automatically destroying old records](#automatically-destroying-old-records) for more information.
* `ignored_errors` - Error classes, or their names, to never record, in addition to the built-in list in `SolidErrors::Subscriber::IGNORED_ERRORS`. For example, `config.solid_errors.ignored_errors = ["ActiveStorage::FileNotFoundError"]`.

### Database Configuration

Expand Down Expand Up @@ -388,4 +389,3 @@ The gem is available as open source under the terms of the [MIT License](https:/
## Code of Conduct

Everyone interacting in the SolidErrors project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fractaledmind/solid_errors/blob/main/CODE_OF_CONDUCT.md).

1 change: 1 addition & 0 deletions lib/solid_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module SolidErrors
mattr_accessor :email_to
mattr_accessor :email_subject_prefix
mattr_accessor :destroy_after
mattr_accessor :ignored_errors, default: []

class << self
# use method instead of attr_accessor to ensure
Expand Down
2 changes: 1 addition & 1 deletion lib/solid_errors/subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def s(data)
end

def ignore_by_class?(error_class_name)
IGNORED_ERRORS.any? do |ignored_class|
[*IGNORED_ERRORS, *SolidErrors.ignored_errors].any? do |ignored_class|
ignored_class_name = ignored_class.respond_to?(:name) ? ignored_class.name : ignored_class

ignored_class_name == error_class_name
Expand Down
34 changes: 34 additions & 0 deletions test/solid_errors/subscriber_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require "test_helper"

class SolidErrors::SubscriberTest < ActiveSupport::TestCase
CustomError = Class.new(StandardError)

teardown do
SolidErrors.ignored_errors = []
end

test "errors named in ignored_errors are not recorded while others are" do
SolidErrors.ignored_errors = [CustomError.name]

Rails.error.report(CustomError.new("ignored"))
Rails.error.report(StandardError.new("recorded"))

assert_equal ["StandardError"], SolidErrors::Error.pluck(:exception_class)
end

test "ignored_errors accepts classes as well as names" do
SolidErrors.ignored_errors = [CustomError]

Rails.error.report(CustomError.new("ignored"))

assert_empty SolidErrors::Error.all
end

test "the built-in ignored errors still apply alongside ignored_errors" do
SolidErrors.ignored_errors = [CustomError.name]

Rails.error.report(ActiveRecord::RecordNotFound.new("ignored"))

assert_empty SolidErrors::Error.all
end
end
Loading