Skip to content
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

airbrake-ruby: return nil instead of raising error #75

Merged
merged 1 commit into from
May 5, 2016

Conversation

kyrylo
Copy link
Contributor

@kyrylo kyrylo commented May 5, 2016

Fixes airbrake/airbrake#546
(Disable Airbrake when not configured?)

This is probably the most annoying thing about this library. People
often don't see the original error when we raise ours (the original
error becomes nested and it is hard to notice). Sometimes users also
want to disable Airbrake, but they can't do so because once the library
is required, it assumes that the user wants to configure it
immediately. So if you don't configure it, your app crashes.

The solution is to stop raising this error. If not the complaints, I
would probably leave it as is. The current behaviour makes a lot of
sense to me. However the amount of confusion is immense, so "we must
deal with it".

@kyrylo kyrylo force-pushed the 546-default-notifier-error-fix branch 3 times, most recently from 5ad79ba to d4b09cd Compare May 5, 2016 01:17
raise Airbrake::Error,
"the '#{notifier}' notifier isn't configured"
unless @notifiers.key?(notifier)
return { 'error' => "the '#{notifier}' notifier isn't configured" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be helpful to explain the consequences in this message, to help explain what this means and to help decide if they want to fix it? Also, is it obvious to the user that this is related to Airbrake? Maybe something like: { 'error' => "the '#{notifier}' notifier isn't configured, Airbrake will not be notified of errors" }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be helpful to explain the consequences in this message, to help explain what this means and to help decide if they want to fix it?

You mean, in the readme?

Also, is it obvious to the user that this is related to Airbrake

I guess it can be more obvious, yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, in the readme?

No, in the message. I tried to resolve both points I made with my suggestion.

Copy link
Contributor Author

@kyrylo kyrylo May 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about: **Airbrake: the '#{notifier}' notifier isn't configured, '#{method}' was not called.

This error can occur even if you call add_filter, for example. So if you call that and see Airbrake will not be notified of errors, it might be a little bit confusing. On the other hand, I doubt anybody will be checking the return value of add_filter or any other value than notify_sync. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I like it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amended the message.

@kyrylo kyrylo force-pushed the 546-default-notifier-error-fix branch 2 times, most recently from 66e5b20 to 64727dc Compare May 5, 2016 12:18
@kyrylo
Copy link
Contributor Author

kyrylo commented May 5, 2016

PTAL

return {
'error' => "#{LOG_LABEL} the '#{notifier}' notifier isn't configured, " \
"'#{method}' was not called"
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to log the same error message? What is the point of returning this if none really will handle it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about doing it like so, but the problem is that we log through user configured loggers, via @config.logger.debug(...). If none of the notifiers exist, it also means loggers don't exist. I thought about logging to STDERR, but decided not to do so because there's a risk of polluting it with countless messages, which is something that people who want to disable Airbrake would hate.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The just remove this return. None will ever use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We still need to return early in order to prevent execution (which will crash), so I assume you want to remove the hash
  2. I can see your point and I partially agree with it, but my question is what harm will this hash introduce? If nobody uses the return value, it's still useful. If a customer complains that Airbrake doesn't send errors, my first question will be "what is the return value?". Think of it as a support tool.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong to me, because now every notifier method can return hash {error: "qqqq"} (even method that return bool etc) and that is a bad design.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stopped returning the Hash. PTAL

@kyrylo kyrylo force-pushed the 546-default-notifier-error-fix branch from 43bf37d to 146fcdf Compare May 5, 2016 13:58
Fixes airbrake/airbrake#546
(Disable Airbrake when not configured?)

This is probably the most annoying thing about this library. People
often don't see the original error when we raise ours (the original
error becomes nested and it is hard to notice). Sometimes users also
want to disable Airbrake, but they can't do so because once the library
is required, it assumes that the user wants to configure it
immediately. So if you don't configure it, your app crashes.

The solution is to stop raising this error. If not the complaints, I
would probably leave it as is. The current behaviour makes a lot of
sense to me. However the amount of confusion is immense, so "we must
deal with it".
@kyrylo kyrylo force-pushed the 546-default-notifier-error-fix branch from 146fcdf to d3f04d3 Compare May 5, 2016 14:01
@kyrylo kyrylo changed the title airbrake-ruby: return error instead of raising it airbrake-ruby: return nil instead of raising error May 5, 2016
@vmihailenco
Copy link

LGTM, but I would add a log message

@kyrylo
Copy link
Contributor Author

kyrylo commented May 5, 2016

Added a log message.

@kyrylo kyrylo merged commit 7ab9419 into master May 5, 2016
@khustochka
Copy link

khustochka commented May 5, 2016

After trying this branch I am getting this (when Airbrake is not configured):

undefined method `[]' for nil:NilClass

airbrake (5.2.3) lib/airbrake/rack/notice_builder.rb:49:in `block in <class:NoticeBuilder>'
airbrake (5.2.3) lib/airbrake/rack/notice_builder.rb:43:in `block in build_notice'
airbrake (5.2.3) lib/airbrake/rack/notice_builder.rb:43:in `each'
airbrake (5.2.3) lib/airbrake/rack/notice_builder.rb:43:in `build_notice'
airbrake (5.2.3) lib/airbrake/rack/middleware.rb:38:in `notify_airbrake'
airbrake (5.2.3) lib/airbrake/rack/middleware.rb:24:in `rescue in call'
airbrake (5.2.3) lib/airbrake/rack/middleware.rb:21:in `call'

@kyrylo
Copy link
Contributor Author

kyrylo commented May 5, 2016

@khustochka thanks for letting me know! I'll prepare a fix tomorrow.

kyrylo added a commit to airbrake/airbrake that referenced this pull request May 9, 2016
This change along with airbrake/airbrake-ruby#75
fix #546.

Due to the breaking change in airbrake-ruby we need to update some of
our integrations that use `Airbrake.build_notice`.
kyrylo added a commit to airbrake/airbrake that referenced this pull request May 9, 2016
This change along with airbrake/airbrake-ruby#75
fix #546.

Due to the breaking change in airbrake-ruby we need to update some of
our integrations that use `Airbrake.build_notice`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants