Created
September 17, 2025 08:28
-
-
Save 42LM/6a96fb9e37d431d7cada273c4b8f3510 to your computer and use it in GitHub Desktop.
go multierror
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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