Live data from Hacker News

Unwrapit provides a way to handle errors in JS/TS

musicq.gitbook.io

1–10 of 72 posts

Re: Unwrapit provides a way to handle errors in JS/TS

#6
post #2

Spent sometime to complete the document of my rust Result like library `unwrapit` for JS/TS. Still think this might be a proper way to deal with errors in JS/TS

This is awesome! I dig this when using Rust and am pumped to try and sneak this in at work where we have a large TS codebase.

Re: Unwrapit provides a way to handle errors in JS/TS

#8
Why not expect that something would throw at some point where app logics are taking place and wrap with try-catch at your lower layer and handle uncaught errors there?

Adding all these boilerplate that not all people agree with would just make it harder to read and debug.

Re: Unwrapit provides a way to handle errors in JS/TS

#9
Just use a library that already contains this and more functional programming idioms, like fp-ts or its successor, Effect [0]. It is a little more complex to learn but much more robust that simply implementing your own Result and other types.

[0] https://www.effect.website/

Re: Unwrapit provides a way to handle errors in JS/TS

#10
post #2

Spent sometime to complete the document of my rust Result like library `unwrapit` for JS/TS. Still think this might be a proper way to deal with errors in JS/TS

I think the idea of try/catch is to let the error bubble up to the place where it can be handled. It usually results into having error handling in a few central places. Your example in github is IMO not how to make best use of try/catch.

Here’s lots of typical exception handling patterns: http://wiki.c2.com/?ExceptionPatterns

Persobally I prefer exceptions over boilerplate “if’s”, but good to know that there’s a wrapper for the people who don’t.

Post reply on HN