Skip to content

Re-enable unhandledrejection Sentry logging and fix `undefined` message

.

Fixing undefined message Sentry events

Example events,

This was caused by the built-in Raven.js error handling Bluebird errors that are not spec compliant, missing PromiseRejectionEvent -> e.reason. Bluebird promises use e.detail.reason. The only Bluebird docs I could find around e.detail was "parameters are properties of the event detail property". There is an issue to track spec-compliance, https://github.com/petkaantonov/bluebird/issues/1509, and we just need to wait for a new Bluebird version.

They even mention Bluebird by name as should be working fine.

Bluebird and other promise libraries report unhandled rejections to a global DOM event, unhandledrejection. In this case, you don't need to do anything, we've already got you covered by with default captureUnhandledRejections: true setting.

https://github.com/getsentry/raven-js/blob/master/docs/usage.rst#promises

Here are some barebones demos that show off e.reason vs e.detail.reason


I disabled the built-in Raven.js unhandledrejection handling with the captureUnhandledRejections Raven config. Then re-enabled our own custom unhandledrejection handling which was previously disabled because halley was polluting Sentry. halley is now up-to-date in gitter-realtime-client so we are all good there.

Testing

I tested that we no longer get undefined Sentry messages (just cause any uncaught error).

I tested that TransportError and BayeuxError are ignored,


function defineProperty(obj, name, value) {
  Object.defineProperty(obj, name, {
    value: value,
    configurable: true,
    enumerable: false,
    writable: true
  });
}
function BayeuxError(message) {
if (!(this instanceof BayeuxError)) return new BayeuxError(message);
var code, params, m;
message = message || '';
var match = /^([\d]+):([^:]):(.)$/.exec(message);
if (match) {
code   = parseInt(match[1], 10);
params = match[2].split(',');
m      = match[3];
}
defineProperty(this, "message", m || message || "bayeuxError");
defineProperty(this, "name", "BayeuxError");
defineProperty(this, "code", code);
defineProperty(this, "params", params);
defineProperty(this, "bayeuxMessage", m);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
} else {
Error.call(this);
}
}
BayeuxError.prototype = Object.create(Error.prototype);
BayeuxError.prototype.constructor = BayeuxError;
Promise.resolve()
.then(() => {
throw new BayeuxError('some error');
});


Closes https://gitlab.com/gitlab-org/gitter/webapp/issues/1889, https://github.com/troupe/gitter-webapp/issues/1056

Edited by Eric Eastwood

Merge request reports