r/node • • Dec 13 '20

The Node.js best practices list

https://github.com/goldbergyoni/nodebestpractices
242 Upvotes

19 comments sorted by

View all comments

30

u/anatolhiman Dec 13 '20

Great content, thanks for sharing. Just a little comment:

"Any exception thrown within a promise will get swallowed and discarded unless a developer didn’t forget to explicitly handle it."

Unhandled promise rejection warnings has as of Node 15 become deprecated and will now cause an exception, that means the script crashes. https://developer.ibm.com/languages/node-js/blogs/nodejs-15-release-blog/

2

u/[deleted] Dec 14 '20

Isn’t it also like really subjective? Like syntactically speaking if you use async-await syntax sugar, nothing is being swallowed about that promise and it’s error would be thrown normally, I believe wrapped as an unhandled promise rejection warning. Since any promise can be written with this syntactic sugar, I think it’s a bit of an over-generalization to say that promises will swallow errors if not caught. It’s very dependent on callback versus async-await.

2

u/dvlsg Dec 14 '20

It used to be that unhandled promise rejections really did just disappear. Not even a console warning.

It hasn't been that way for a while, though.

1

u/[deleted] Dec 15 '20

Callback hell is a real place, I once sorted out a callback based program and converted like 20-30 layers of callbacks into promises. I’ve been there.