3

I'm adding Raygun error handling to my Aurelia application and just realized that I'm not able to catch errors which occur during app setup (e.g. within main.configure).

Here's the code which is not using Raygun at all but simply tries to catch all errors:

index.html

<!DOCTYPE html>
<html>
<head>
    <!-- ... -->
</head>

<body aurelia-app="main">
<script src="build/res/vendor-bundle.js" data-main="aurelia-bootstrapper"></script>
<script type="text/javascript">
    window.onerror = function() {
        console.info('arguments:', arguments);
    }
</script>
</body>
</html>

main.ts

// ...
export function configure(aurelia: Aurelia) {
    aurelia.use
        .standardConfiguration()
        .feature('resources');

    // ...

    blah.this = 3; // <-- Force some error...
}

The error is logged in the console but the onerror handler in my index file is not called. Also Aurelias internal ConsoleAppender.Error is not called since I guess its not configured/activated at this stage.

Following the stack trace in the dev tools leads me to this code...

function tryCatcher() {
    try {
        var target = tryCatchTarget;
        tryCatchTarget = null;
        return target.apply(this, arguments);
    } catch (e) {
        errorObj.e = e;
        return errorObj;
    }
}

... which I guess comes from Bluebird...

How can I reliably catch all errors in my app?


Here's a screenshot of the logged error:

enter image description here

  • vendor-bundle.js:3411 leads to the tryCatcher mentioned above
  • app-bundle.js:72:9 (1st entry in stacktrace) leads to the actual error line blah.this = 3
  • Bluebirds unhandledRejection & rejectionHandled events are not fired in this scenario...
suamikim
  • 5,350
  • 9
  • 40
  • 75
  • How is it logged in the console, as an "unhandled *rejection*"? – Bergi Mar 31 '17 at 13:08
  • @Bergi I've added a screenshot of the logged error. It's not logged as an unhandled rejection. I've already tried to catch bluebirds `unhandledRejection` and `rejectionHandled` [events](http://bluebirdjs.com/docs/api/error-management-configuration.html#global-rejection-events) which are not fired in my scenario above. – suamikim Apr 03 '17 at 07:25
  • Hm, weird. Maybe you need to set up the `window.onerror` handler before loading the bundle? – Bergi Apr 03 '17 at 10:03
  • Moving the script which sets up the `onerror` handler before the bundle loader doesn't work either. I've also checked that the `onerror` handler is actually installed before the error occurs. – suamikim Apr 03 '17 at 14:06

0 Answers0