rollbar / rollbar.js

Error tracking and logging from Javascript to Rollbar

Home Page:https://docs.rollbar.com/docs/javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Callback is not always invoked in `rollbar.js/src/rollbar.js:Rollbar.prototype._log`

sam-perez opened this issue · comments

For reference, link to relevant code I'm referring to is here:

this.logger.error(e);

I just spent the last few hours tracking down an issue. I had errors that were being logged by my other Winston transports, but they were not appearing in Rollbar. After reproing the issue locally, I attempted to console.log right before I logged the errors to Rollbar as well as registering a callback with Rollbar.error that would log out the result of the call. The callback function never got invoked. After deep diving into the source, I figured out that the error I was attempting to log had a nested error that was set to null.

do {
    errors.push(err);
    err = err.nested;
  } while (err !== undefined);

The above code was throwing an error since err was null (self explanatory).

The problem is in rollbar.js/src/rollbar.js:

try {
    this._addTracingInfo(item);
    item.level = item.level || defaultLevel;
    this.telemeter && this.telemeter._captureRollbarItem(item);
    item.telemetryEvents = (this.telemeter && this.telemeter.copyEvents()) || [];
    this.notifier.log(item, callback);
  } catch (e) {
    this.logger.error(e); //  <---- callback is not called here with the error!!!!
  }

The catch block does not invoke the callback with the error if there is an error during the try block. Now, I'm not proposing a solution, I'm just saying that the contract of the callback is being broken here. In all cases, the callback should be called, and there are cases where it is not called. Plz fix and save some other poor engineers time in debugging issues they encounter.

@sam-perez Thank you for the debugging effort.