-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filter with raw exception instance #241
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a cool change 👍
I've been thinking about doing this, but there was no user demand, so I thought it wasn't needed.
It would be nice to add a test for the change, then I can merge the PR. Thanks!
README.md
Outdated
if notice[:errors].any? { |error| error[:type] == 'StandardError' } | ||
notice.ignore! | ||
end | ||
notice.ignore! if notice.exception.kind_of? StandardError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use brackets around .kind_of?(StandardError)
. We prefer this style in this project.
lib/airbrake-ruby/notice.rb
Outdated
@@ -62,7 +62,7 @@ class Notice | |||
# @since v1.7.0 | |||
# @return [Hash{Symbol=>Object}] the hash with arbitrary objects to be used | |||
# in filters | |||
attr_reader :stash | |||
attr_reader :stash, :exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably move this on a separate line because the comment above describes :stash
.
Failed on Rubocop. How can I avoid it? |
We don't reuse them, so there's no need for them to be separate methods. Besides, this will decrease class length, so we don't introduce any Rubocop offences (#241)
README.md
Outdated
if notice[:errors].any? { |error| error[:type] == 'StandardError' } | ||
notice.ignore! | ||
end | ||
notice.ignore! if notice.exception.kind_of?(StandardError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubocop wants is_a?
instead of kind_of?
. They are aliases, so let's use is_a?
.
spec/notifier_spec.rb
Outdated
@@ -514,6 +514,20 @@ def to_json(*) | |||
@airbrake.notify_sync(ex) | |||
expect(a_request(:post, endpoint)).to have_been_made.once | |||
end | |||
|
|||
it "ignores descendant classes" do | |||
class AirbrakeTestSubError < AirbrakeTestError; end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AirbrakeTestSubError
can be a local variable:
descendant = Class.new(AirbrakeTestError)
It is preferred, so we don't pollute namespaces with constants.
To fix the |
lib/airbrake-ruby/notice.rb
Outdated
@@ -64,6 +64,10 @@ class Notice | |||
# in filters | |||
attr_reader :stash | |||
|
|||
## | |||
# @return [Exception] raw exception | |||
attr_reader :exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about putting this into @stash.exception
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why not. @kuboon, that will probably the preferred solution. Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem. I did not understand what is stash
for.
use is_a? instead of kind_of?
You can run Rubocop locally.
|
Great work, thanks 👍 |
README shows following example to ignore
StandardError
But we rarely raise
StandardError
itself.Instead, we raise the descendants of
StandardError
.Current implementation converts the exception to a string value before filtering.
It looses class hierarchy.
This patch allows filter to use exception instance to do like this: