DEV Community

Discussion on: Error Handling in JavaScript (Golang Style)

Collapse
 
grzegorzbielski profile image
Grzegorz Bielski

I'm not a huge fan of this pattern.
The idea of explicitly returning errors rather than throwing unchecked errors is great, but the proposed implementation is flawed - we need to always check the elements of the tuple before using the value to see if there is an error which will become error-prone rather quickly.
Fortunately, this is an already solved problem, known in other langues as Either or Result type, in which all of these ifs are abstracted away in form of map and flatMap / chain operations.
Potential implementation: gigobyte.github.io/purify/adts/Eit...

Collapse
 
bibekkakati profile image
Bibek

Got your point. After all it's all about own preference.