Error handling
Error trees and multiple causes
A joined error can expose multiple underlying errors. Matching via errors.Is searches the error tree, whereas errors.Unwrap only calls the single-error Unwrap() error method and therefore does not traverse a joined error. Join ignores nil inputs. Example output: 'true true true'.
Formal Syntax & Structure
go syntaxgo
errors.Join(err1, err2)Working Example
Example Snippetgo
package main
import "fmt"import "errors"
func main() { a := errors.New("a") b := errors.New("b") e := errors.Join(a, nil, b) fmt.Println(errors.Is(e, a), errors.Is(e, b), errors.Unwrap(e) == nil)}