Logging doesn't work when an error is thrown in a lifetime event


#1

Anyone else have a problem getting console logs when an error happens in a lifetime event (e.g. created, attached, etc.)? My problem can be reproduced by scaffolding a new project using typescript, scss, and webpack. Then, in the app.ts file, add an attached() event and inside it throw a new Error. The event handler method terminates immediately, as you would expect. However, the Error doesn’t get logged to the console. If you add a button with a click handler and throw the Error in that method, then it does get logged. It also doesn’t log errors if the error occurs in the then() handler for a Promise if the promise was created inside a lifetime event handler. This is where the real problem is. If a server callback fails, I don’t get a log of it, because we usually call the server routines in the lifetime events…


#2

Aurelia life-cycle callbacks are wrapped in promise by Aurelia, when it throw error, it becomes an unhandled rejection. So there is no difference between throw error directly or throw error inside .then() call.

Bluebird by default logs them, do you have special bluebird config file that suppresses unhandled rejection?


#3

Well, unfortunately, when using bluebird, some pages take 30+ seconds to load in IE11. And even those that load faster are still significantly slower with bluebird than with es6-promise. Unfortunately about 40% of our clients are still using IE11, so I can’t make the switch yet. I did convert back to bluebird just to verify, and I can confirm that when an Error is thrown in a lifetime event handler, the errors ARE being logged. Looks like this is an issue for es6-promise.

Anyone have suggestions for other Promise polyfills they like and that work well with IE11 ?


#4

It is not an issue of es6-promise and native promise. The promise spec doesn’t require log unhandled rejects. It is bluebird’s own behavior.

Sometimes I am also annoyed by aurelia not handling lifecycle rejection. Probably a PR to log rejections is a better way moving forward.