News for hackers. Stuff that matters.
Re:ESLint 7.0 by aaomidi on Monday May 11, 2020 @01:13PM (#23144444)
There is a rule in eslint that warns you when a promise is dangling and hasn't been handled.

Please use that rule. So many bugs in the JS world is because of dangling promises.

Re:ESLint 7.0 by nfriedly on Monday May 11, 2020 @02:55PM (#23145628)
I think that's part of the typescript plugin, not part of eslint core - https://github.com/typescript-eslint/typescript-eslint/blob/... (I assume that means it only works on TypeScript.)

But, I agree with your point, that rule can catch a lot of bugs.

Re:ESLint 7.0 by krainboltgreene on Monday May 11, 2020 @03:49PM (#23146193)
There are many ways to get this rule, but the primary one being: https://www.npmjs.com/package/eslint-plugin-promise
Re:ESLint 7.0 by vimslayer on Monday May 11, 2020 @06:53PM (#23148149)
I don't think that plugin catches floating promises, i.e. promises that are not waited (either via await or then/catch method). The rules listed in that package's readme don't seem to mention it at least (unless I'm totally misreading something). You kinda need TypeScript for that because you need the type info to know if a value whether some value is a Promsie to give the warning.
Re:ESLint 7.0 by zymhan on Monday May 11, 2020 @01:55PM (#23144945)
We use Pulumi and Typescript, and it seems to rely heavily on Promise. I wonder how that ESLint rule would affect Pulumi code?

https://www.pulumi.com/docs/intro/concepts/programming-model...

Re:ESLint 7.0 by dfee on Monday May 11, 2020 @02:27PM (#23145348)
I’m not sure on Pulumi specifically, but a .catch on a non-awaited promise should be fine.
Re:ESLint 7.0 by z3t4 on Monday May 11, 2020 @03:43PM (#23146130)
If you add a catch block it will be even worse, all errors inside a promise callback will then become soft errors. Only add the catch if you actually plan to handle the error.
Re:ESLint 7.0 by hombre_fatal on Tuesday May 12, 2020 @12:50AM (#23150681)
promise.catch(console.error) is still handling the error.
Re:ESLint 7.0 by z3t4 on Tuesday May 12, 2020 @11:30AM (#23155026)
That's still a soft error. Meaning the app will continue like if nothing happened. Resulting in poisonous state.
Re:ESLint 7.0 by tengbretson on Monday May 11, 2020 @03:13PM (#23145805)
I can't speak to the front-end, but there are plenty of situations in dealing with node where the correct thing to do is to throw a fatal error. If you have properly setup handlers for the end of the process lifecycle I don't see what the problem is.
Re:ESLint 7.0 by ergothus on Monday May 11, 2020 @03:27PM (#23145965)
But until recently an unhandled promise failure was NOT a thrown error, and when it is it's not the error you want.
Re:ESLint 7.0 by tengbretson on Monday May 11, 2020 @04:08PM (#23146402)
Absolutely! I guess what I'm trying to say is that in my experience, crashing on an unhandled rejection is a better remedy to the dangling promise problem than banning them outright.
Re:ESLint 7.0 by z3t4 on Monday May 11, 2020 @03:49PM (#23146188)
There is a saying - what you don't know can't hurt you. The idea of Promises comes from strongly typed static functional languages. Adding it to JavaScript was a terrible idea. Like with static modules - forcing the user to download the whole website/app before anything is rendered on the screen.
Re:ESLint 7.0 by aaomidi on Monday May 11, 2020 @05:24PM (#23147265)
Lol what are you on about.

You're mixing so many different things right now.

Re:ESLint 7.0 by ausjke on Monday May 11, 2020 @01:40PM (#23144762)
hundreds of rules to read, is this on its recommended list if it's so critical? is its name 'no-floating-promises'?
Re:ESLint 7.0 by williamdclt on Monday May 11, 2020 @01:50PM (#23144897)
> is its name 'no-floating-promises'

Yes, and I subscribe to the parent's sentiment: this rule is essential

Re:ESLint 7.0 by brycelarkin on Monday May 11, 2020 @04:27PM (#23146617)
Re:ESLint 7.0 by aaomidi on Monday May 11, 2020 @02:41PM (#23145487)
It's unfortunately not on the recommended list. For very few circumstances the rule doesn't make sense, but most of the time that shows bad programming design.

That's the name!

Re:ESLint 7.0 by aaomidi on Monday May 11, 2020 @09:30PM (#23149604)
I also highly recommend just reading all the rules if you're a JS/TS developer. It really helps you see what stuff could be very useful.
Re:ESLint 7.0 by johnsoft on Monday May 11, 2020 @07:01PM (#23148252)
>is this on its recommended list

Not now, but it's planned to be starting with the next major version. They are holding off until then since changing the default rules is considered a breaking change.

https://github.com/typescript-eslint/typescript-eslint/issue...

Re:ESLint 7.0 by dang on Monday May 11, 2020 @05:09PM (#23147102)
Please don't use uppercase for emphasis. If you want to emphasize a word or phrase, put asterisks around it and it will get italicized.

https://news.ycombinator.com/newsguidelines.html.

Re:ESLint 7.0 by edflsafoiewq on Monday May 11, 2020 @06:45PM (#23148044)
HNLint
Re:ESLint 7.0 by aaomidi on Monday May 11, 2020 @07:21PM (#23148513)
Thanks!

HN should automatically detect this and let me know :D

Unfortunately I think the comment is too old to edit.

Re:ESLint 7.0 by dang on Monday May 11, 2020 @08:26PM (#23149187)
> HN should automatically detect this and let me know

That's on the list!

I've reopened the comment for editing if you still want to.

Re:ESLint 7.0 by aaomidi on Monday May 11, 2020 @09:30PM (#23149597)
Done! Thanks :)