Created
September 9, 2025 11:39
-
-
Save 42LM/1506a24d825fc0923be709ebb3bf2f78 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