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)
Karl
(Karl)
July 3, 2025, 8:30pm
2
for example.
A Go (golang) package for representing a list of errors as a single error.
Combine one or more Go errors together
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:
package dotconfig
import (
"fmt"
"strings"
)
// Simple wrapper for multiple errors. This definition matches the uderlying
// type that [errors.Join] introduced in go 1.20:
// - https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/errors/join.go;l=40
type joinError struct {
errs []error
}
// HasErrors will return true if any of the errors in underlying
// errs slice are non-nil.
func (je *joinError) HasErrors() bool {
for _, err := range je.errs {
if err != nil {
return true
This file has been truncated. show original
You could copy/paste that and use it as a starting point.
1 Like