Skip to content

Strip Raven's wrapped try/catch call from frames [WIP] #581

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Raven.prototype = {
return func.apply(this, args);
} catch(e) {
self._ignoreNextOnError();
self.captureException(e, options);
self.captureException(e, options, 1);
throw e;
}
}
Expand Down Expand Up @@ -310,9 +310,11 @@ Raven.prototype = {
* @param {object} options A specific set of options for this error [optional]
* @return {Raven}
*/
captureException: function(ex, options) {
captureException: function(ex, options, skipframes) {
skipframes = skipframes || 0;

// If not an Error is passed through, recall as a message instead
if (!isError(ex)) return this.captureMessage(ex, options);
if (!isError(ex)) return this.captureMessage(ex, options, skipframes + 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Err, this isn't necessary ... yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, by incrementing and passing skipframes to captureMessage, we can generate a new stack by throwing an error from inside captureMessage, slice off skipframes frames, and then we can send that w/ the payload to Sentry. As in, we can now attach valid stack traces alongside captureMessage calls.

I was going to do that in a separate PR.


// Store the raw exception object for potential debugging and introspection
this._lastCapturedException = ex;
Expand All @@ -324,7 +326,7 @@ Raven.prototype = {
// report on.
try {
var stack = TraceKit.computeStackTrace(ex);
this._handleStackInfo(stack, options);
this._handleStackInfo(stack, options, skipframes);
} catch(ex1) {
if(ex !== ex1) {
throw ex1;
Expand All @@ -341,7 +343,7 @@ Raven.prototype = {
* @param {object} options A specific set of options for this message [optional]
* @return {Raven}
*/
captureMessage: function(msg, options) {
captureMessage: function(msg, options, skipframes) {
// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
// early call; we'll error on the side of logging anything called before configuration since it's
// probably something you should see:
Expand Down Expand Up @@ -1005,7 +1007,7 @@ Raven.prototype = {
}
},

_handleStackInfo: function(stackInfo, options) {
_handleStackInfo: function(stackInfo, options, skipframes) {
var self = this;
var frames = [];

Expand All @@ -1016,6 +1018,10 @@ Raven.prototype = {
frames.push(frame);
}
});

if (skipframes) {
frames = frames.slice(0, skipframes);
}
}

this._triggerEvent('handle', {
Expand Down