Why errors are not bubbling up from ES6 promises? (+fix)

I’ve just spent way to much time debugging a node program that was crashing because of a database call wrapped in ES6 promise. After looking all around in my code for an abusive try/catch silencing the error, I stumbled upon an article explaining error Promises swallow errors!handling behavior with ES6 promises, that are just basically “swallowing” all errors thrown during their resolution. While arguable, this behavior is expected as per the specifications.

The following article describes this behavior quite well and provide a workaround: http://jamesknelson.com/are-es6-promises-swallowing-your-errors/

A (safer) promises wrapper

Meanwhile, I’ve put together a wrapper for ES6 Promise, that displays errors as they are raised. I published it on npm as safe-promise. Just use this as your promise lib, and you’ll get the errors back.

Check out the npm page: https://www.npmjs.com/package/safe-promise

I hope that sharing this will save you some time and headaches.

Why errors are not bubbling up from ES6 promises? (+fix) was last modified: December 27th, 2016 by Tom Guillermin

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.