Created
February 20, 2023 15:09
-
-
Save marvinhosea/0389473351013e631b53c3178fdc3e4a to your computer and use it in GitHub Desktop.
Example
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" | |
"log" | |
) | |
var ( | |
errOne = errors.New("error one") | |
errTwo = errors.New("error two") | |
) | |
func main() { | |
fmtErrs := fmt.Errorf("error: %w, %w", errOne, errTwo) | |
joinErrs := errors.Join(errOne, errTwo) | |
log.Println(errors.Unwrap(joinErrs)) | |
log.Println(errors.Unwrap(fmtErrs)) | |
j, jok := joinErrs.(interface{ Unwrap() []error }) | |
f, fok := fmtErrs.(interface{ Unwrap() []error }) | |
log.Println(j.Unwrap(), jok) | |
log.Println(f.Unwrap(), fok) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment