Skip to content

Instantly share code, notes, and snippets.

@marvinhosea
Created February 20, 2023 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marvinhosea/0389473351013e631b53c3178fdc3e4a to your computer and use it in GitHub Desktop.
Save marvinhosea/0389473351013e631b53c3178fdc3e4a to your computer and use it in GitHub Desktop.
Example
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