News for hackers. Stuff that matters.
Re:A better way to handle errors in JavaScript by meowtimemania on Tuesday October 31, 2023 @03:50AM (#38081429)
I'd prefer an api like this:

const [result, error] = attempt(() => someFunc());

This way you don't have to wrap all your functions.

Re:A better way to handle errors in JavaScript by tentacleuno on Tuesday October 31, 2023 @03:56AM (#38081464)
That seems a lot more ergonomic.

I can already see someone copy-pasting `wrap(myFunction)(args)` everywhere :-)

Re:A better way to handle errors in JavaScript by musicq on Tuesday October 31, 2023 @07:37AM (#38083222)
I think the most usual way in a project is to use this style. Wrap is a simple way to let you get Result type without refactoring your implementation.

https://musicq.gitbook.io/unwrapit/recipe/return-result-with...

Re:A better way to handle errors in JavaScript by meowtimemania on Tuesday October 31, 2023 @05:19PM (#38091516)
Then I'm tightly coupling all my code to this library. I would prefer to write javascript like normal and not import a library anytime I author a function.
Re:A better way to handle errors in JavaScript by vmfunction on Tuesday October 31, 2023 @03:59AM (#38081484)
have you look at ts-fp, it is ts not js, but still.