DEV Community

loading...

Discussion on: JavaScript: Handling errors like Go

Collapse
jeyj0 profile image
Jannis Jorre

Thanks for the post! I think this is a great pattern to follow.

I have one question left: is there a reason you return the error as first item and not the requested end-value?😇

Collapse
oieduardorabelo profile image
Eduardo Rabelo Author • Edited

thanks for your time Jannis! :)

my first approach was to mimic the Go way, but after it "clicked", I started using it in different ways!

🤗

Collapse
jeyj0 profile image
Jannis Jorre

Is there a reason though?🤔

Thread Thread
oieduardorabelo profile image
Eduardo Rabelo Author

the reason was to mimic Go... after switching between JavaScript and Go projects, I felt the need to try to write in a similar way in JavaScript :P

Thread Thread
jeyj0 profile image
Jannis Jorre

I got that - sorry if I wasn't clear enough, let me rephrase my question:

Is there a reason to go for a return that can be destructered as [err, value] over one that would be destructered with [value, err]?

I hope I made it understandable now.😇