Skip to content
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

Callback to set options depending on captured exception #972

Closed

Conversation

TimPetricola
Copy link

When throwing an error, it sometimes make sense to add some extra data directly to the Error object like so:

const error = new Error('foo')
error.extra = {foo: 'bar'}
throw error

Right now, if we want this extra sent alongside the error, we need to override Raven.captureException like so:

const originalCaptureException = Raven.captureException.bind(Raven)
Raven.captureException = (ex, options) => {
  options = Object.assign({}, options)
  options.extra = Object.assign({}, ex.extra, options.extra)
  originalCaptureException(ex, options)
}

With this PR, it allows us to replace this overriding with a simple config:

Raven.config(SENTRY_DSN, {
  optionsFromException(ex, options) {
    options = Object.assign({}, options)
    options.extra = Object.assign({}, ex.extra, options.extra)
    return options
  }
})


assert.isTrue(Raven._handleStackInfo.calledWith(
// sinon sandbox does not exposes match property before sinon 2.0
sinon.match.any,
Copy link
Author

Choose a reason for hiding this comment

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

Could be replaced by this.sinon.match.any if Sinon is updated to >= 2.0 (support added in sinonjs/sinon#1076)

@dcramer
Copy link
Member

dcramer commented Jun 6, 2017

Would it be good enough if dataCallback (or similar) just passed along the error object, and you were able to then augment the Sentry payload from there?

@LewisJEllis
Copy link
Contributor

LewisJEllis commented Jun 6, 2017

2 things I can think of that we should consider this against:

  1. We already do something like this completely automatically in raven-node: any additional properties of the error object are added to the extra data. Source here; this PR, is, of course, more flexible, but we're generally averse to introducing new callback hooks without good reason because we could easily end up with 10 of them which would be hard to keep straight.

  2. I can't find the issue right now, but I'm almost certain that we've gotten a request in the past to provide the error object as an argument in dataCallback/shouldSendCallback, and I think @dcramer made a comment against it on the notion that error object should be long since parsed/forgotten by the time we get that far. I'll keep looking for this issue.

@dcramer
Copy link
Member

dcramer commented Jun 6, 2017

I want the error object in a callback per Slack convo. It's non trivial to do today, but it's the right solution.

@TimPetricola
Copy link
Author

I totally see your point in not having too many callbacks. Having access to the error object in dataCallback would certainly be enough and would be perfect to centralize everything in this callback. I was also under the impression that the error object should be parsed at this point though.
Also, at this point, we could be dealing with an error or a message, so the signature should be flexible enough to handle either of them.

@TimPetricola
Copy link
Author

Actually I'm wondering if it would not make more sense to introduce the same behavior as in raven-node for consistency?

@TimPetricola
Copy link
Author

Any update on what we could do on this one? :)

@kamilogorek
Copy link
Contributor

@benvinegar @dcramer was there a consensus whether we should expose error object itself in dataCallback or not?

@dcramer
Copy link
Member

dcramer commented Sep 13, 2017

@kamilogorek IMO we should if we can. It makes it possible to do a lot more behavior by inspecting the object that you otherwise can't reasonable do.

@benvinegar
Copy link
Contributor

We absolutely should, the only reason I waffled on this was that the dataCallback signature is getting bloated and was trying to think of a clever way to represent it. Also, whatever you do, you have to remember about all the other callbacks: shouldSendCallback (sigh) and breadcrumbCallback (where we should show the original object being "breadcrumbed", if it exists e.g. XHRs).

@kamilogorek
Copy link
Contributor

Effectively duplicate of #980

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants