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:
vendor-bundle.js:3411
leads to thetryCatcher
mentioned aboveapp-bundle.js:72:9
(1st entry in stacktrace) leads to the actual error lineblah.this = 3
- Bluebirds
unhandledRejection
&rejectionHandled
events are not fired in this scenario...