sentry-javascript: Automatically log all thrown errors?

Is there a way to get Raven to log all thrown errors? For some reason, it logs some throw calls but not others. I found that it tends to not log behavior that is nested further down the call stack.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 31 (16 by maintainers)

Most upvoted comments

Here you go:

var __hasProp = {}.hasOwnProperty,
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

window.Error = (function(_super) {

  __extends(_Class, _super);

  function _Class() {
    var error;
    error = _Class.__super__.constructor.apply(this, arguments);
    Raven.captureException(error);
    return error;
  }

  return _Class;

})(Error);

It all depends really on the callstack. When things start going into async land, it gets rough. For example, this would not do as expected:

Raven.context(function() {
  setTimeout(function() {
    throw new Error('crap');
  }, 1);
});

The internal function gets run in it’s own context outside of the main context. Node.js solves this with a thing called “domains”, but sadly, those don’t exist in browser land.

So if an error is uncaught and bubbles all the way to the top, it usually gets rejected because it’s 100% worthless at that point.