Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Cawllec/fix shouldnt notify logging #113

Merged
merged 9 commits into from
Sep 1, 2017

Conversation

Cawllec
Copy link
Contributor

@Cawllec Cawllec commented Aug 31, 2017

Disables delivery errors in the case that shouldNotify is false, adds configuration option to overwrite this behaviour if necessary

Copy link
Contributor

@bengourley bengourley left a comment

Choose a reason for hiding this comment

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

In addition to the inline comments I'm also concerned about the following issues:

  • The default log level is "error" so calls logger.warn are likely to be missed, unless the user has set their own log level. We could change the default log level to be "warn" or call logger.error with this message. Both of which seem ugly but would solve the problem.

  • I'm not sure if this PR fixes the user's actual issue which was that errors were masked in development (if I interpreted it correctly). This is because the errors are still caught by the process.uncaughtException handler but then nothing is ever logged out. In short I think they still want a log message in development, but they want the log message of the caught error, not the refusal to deliver to Bugsnag due to configuration.

lib/bugsnag.js Outdated
@@ -92,7 +103,7 @@ Bugsnag.notify = function(error, options, cb) {
options = {};
}
if (!Bugsnag.shouldNotify()) {
if (cb) {
if (cb && Configuration.logAllDeliveryErrors) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this branch could be in a more appropriate place, as the the option mentions log but no logging is done here (an Error object is created and passed to the cb()).

A better place would be in the definition of autoNotifyCallback.

lib/bugsnag.js Outdated
"Bugsnag has not been configured with an api key!");
Configuration.logger.warn(Configuration.logAllDeliveryErrors ?
"Delivery errors will still be reported" :
"Delivery errors will not be reported. Configure logAllDeliveryErrors to change this behaviour");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these log messages are confusing and could be worded better…

Something along the lines of:
"Calls to bugsnag.notify() will silently fail"
or
"Nothing will be sent to Bugsnag. Any bugsnag.notify() calls are essentially NOOPs."

@@ -24,6 +24,7 @@ var Configuration = {
metaData: {},
logger: new Logger(),
sendCode: true,
logAllDeliveryErrors: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of this option might want changing to be consistent with the log message.

@Cawllec
Copy link
Contributor Author

Cawllec commented Aug 31, 2017

Based on discussion with @bengourley I've removed the changes based around the configuration options, and instead ensured that when an error occurs and is correctly not-notified the original error is logged instead of the notification error.

This still leaves the issue with the initial log level however.

@bengourley
Copy link
Contributor

This is better!

Here is how the user's repro repo now behaves:

image

I think it would be good if the error stack got into the log and looked more like how uncaught errors get logged out:

image

appending e.stack to the log message should do the trick?

@Cawllec
Copy link
Contributor Author

Cawllec commented Sep 1, 2017

Appended that stack as suggested and removed the Bugsnag: repetition.

I notice that it's logging each issue twice, any idea why?

lib/bugsnag.js Outdated
Configuration.logger.error("Bugsnag: error notifying bugsnag.com - " + error);
Configuration.logger.error(Bugsnag.shouldNotify() ?
"error notifying bugsnag.com - " + error + error.stack :
"Bugsnag will not be notified - " + notifiedError + notifiedError.stack);
Copy link
Contributor

Choose a reason for hiding this comment

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

notifiedError will be coerced into a string, which will contain the Error: <message> bit, but then the string notifiedError.stack also contains Error: <message> followed by each stack line.

In summary you only need .stack and not both. This goes for line 23 and 24.

I've had a tinker and coming at it from the user's perspective, I think the best output would be something like this…

Bugsnag:  configuration prevents the following error from being sent to Bugsnag.
https://docs.bugsnag.com/platforms/nodejs/other/configuration-options/#notifyreleasestages

Error: Some error occured
    at app.use (/Users/bengourley/Development/bugsnag-bug-repro/index.js:13:11)
    at dispatch (/Users/bengourley/Development/bugsnag-bug-repro/node_modules/koa-compose/index.js:42:32)
    at /Users/bengourley/Development/bugsnag-bug-repro/node_modules/koa-compose/index.js:34:12
    at Server.handleRequest (/Users/bengourley/Development/bugsnag-bug-repro/node_modules/koa/lib/application.js:136:14)
    at emitTwo (events.js:125:13)
    at Server.emit (events.js:213:7)
    at parserOnIncoming (_http_server.js:602:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)

Which you should be able to do with something like…

[
  "configuration prevents the following error from being sent to Bugsnag.",
  "https://docs.bugsnag.com/platforms/nodejs/other/configuration-options/#notifyreleasestages",
  "",
  err.stack
].join('\n')

@bengourley
Copy link
Contributor

LGTM 👍

@bengourley bengourley merged commit a9f99cf into master Sep 1, 2017
@bengourley bengourley deleted the cawllec/fix-shouldnt-notify-logging branch September 8, 2017 10:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants