Intended Behavior of TryCatch Integration?


I’m currently using @sentry/browser@4.5.3 and I’m having some trouble wrapping my head around what should be happening when the TryCatch integration is added to Sentry’s integrations array.

It seems that when this integration is enabled: I set up a context, throw an error, and two events show up in Sentry–only one of the two with the information from the context. My understanding is that TryCatch wraps around several async calls, but should it be sending the two different events or have I likely set something up wrong?

@bunchopunch can you post your config and/or repro case? You shouldn’t get two separate errors.

Thanks, @kamilogorek. And, sorry for the delay–the laptop I was developing on died and it took some time to get the project set back up.

I was just mostly looking for a sanity check, since I hadn’t actually seen the application running before and wasn’t sure exactly what it should look like in a working state. After seeing your response, I went back and changed my implementation a bit. I’ve been building an Angular ErrorHandler service for use in multiple applications and stopped using getCurrentHub within it, as it seemed like there may be two hubs present for some reason in some of the Angular apps. Instead, I made the code look closer to this: Now, things seem to be working as you explained, with single events coming through.

Thanks for detailed explanation. Cheers!

Sorry to pull this thread back up, but there’s another issue that seems related and I figured that if I were the one Google searching for a solution, I would want the full context.

Now I’m using something along these lines in my Angular service:

  // In the component constructor
  const initOptions: Sentry.BrowserOptions = {
    integrations: [
      new this.sentry.Integrations.UserAgent(),
      // ...

  // ... Called by the constructor
  initService = (options: Sentry.BrowserOptions) => {
    const client = new BrowserClient(options);
    this._defaultHub = new Hub(client);

  // ... An example of trying to use the same hub within the service.
  logEvent = (event): void => { this._defaultHub.captureEvent(event); };

As a result, breadcrumbs seem to be missing from the events and the UserAgent integration no longer seems to be working, as there is no request object being appended to the payload sent to Sentry. My guess would be that it has something to do with this GitHub issue, and that the _defaultHub I create and interact with needs to be the global hub. Am I missing some more recent way to designate my _defaultHub as so the global hub so that integrations attach to it, or must I go back to using getCurrentHub?

If I have to go back to getCurrentHub, I will see if I can work up a repro case.