Skip to content

Instantly share code, notes, and snippets.

@42LM
Created September 9, 2025 11:39
Show Gist options
  • Select an option

  • Save 42LM/1506a24d825fc0923be709ebb3bf2f78 to your computer and use it in GitHub Desktop.

Select an option

Save 42LM/1506a24d825fc0923be709ebb3bf2f78 to your computer and use it in GitHub Desktop.
go multierror
package main
import (
"errors"
"fmt"
)
func main() {
err1 := errors.New("error one")
err2 := errors.New("error two")
jErr := errors.Join(err1, err2)
fmt.Printf("Error string: %#v\n", jErr.Error())
if unwrappable, ok := jErr.(interface{ Unwrap() []error }); ok {
unwrappedErrors := unwrappable.Unwrap()
for i, err := range unwrappedErrors {
fmt.Printf("Unwrapped error %d: %#v\n", i, err.Error())
}
} else {
fmt.Println("Error is not unwrappable")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment