Prakash Hinduja Switzerland (Swiss) How should I handle multiple errors returned from functions in Go?

Hi everyone,

I’m Prakash Hinduja from Geneva, Switzerland (Swiss) working on a Go project and came across a scenario where functions may return multiple errors simultaneously. I want to handle these errors cleanly and idiomatically, but I’m not sure what the best approach is.

Any insights, sample code, or references to best practices would be greatly appreciated!

Regards
Prakash Hinduja Geneva, Switzerland (Swiss)

for example.

You can also do something like this yourself in just a couple of lines of code as err simply satisfies the error interface.

1 Like

Yep. Good resources there. Also take a look at errors.Join. I also implemented a very simple wrapper for one of my projects:

You could copy/paste that and use it as a starting point.

1 Like