func ExampleNew_emptyOrNil() { f := func() error { return multierror.New() } err := f() if err != nil { fmt.Println("this is an error for the empty call") fmt.Println(err.Error()) } else { fmt.Println("there is no error for the empty call") } f = func() error { return multierror.New(nil) } err = f() if err != nil { fmt.Println("this is an error for the nil call") fmt.Println(err.Error()) } else { fmt.Println("there is no error for the nil call") } fmt.Println("done") //Output: //this is an error for the empty call // //this is an error for the nil call // //done }
func ExampleMultiError_Append() { err := multierror.New(fmt.Errorf("first error")) err = err.Append(nil) err = err.Append(fmt.Errorf("second error")) fmt.Println(err.Error()) //Output: //first error //second error }
func ExampleMultiError_Raw() { err := multierror.New( fmt.Errorf("first error"), fmt.Errorf("second error"), ) fmt.Printf("%q", err.Raw()) //Output: //["first error" "second error"] }
func ExampleNew() { err := multierror.New( fmt.Errorf("this is an error"), fmt.Errorf("this is another error"), ) fmt.Println(err.Error()) //Output: //this is an error //this is another error }
func ExampleMultiError_ErrorOrNil() { f := func() error { result := multierror.New() return result.ErrorOrNil() } err := f() if err != nil { fmt.Println(err.Error()) } else { fmt.Println("error is nil") } //Output: //error is nil }
func ExampleMultiError_Join() { f := func() error { return multierror.New( fmt.Errorf("first error"), fmt.Errorf("second error"), ) } err := f() if err != nil { fmt.Println(err.Error()) if multiErr, ok := err.(multierror.MultiError); ok { fmt.Println(multiErr.Join(", ")) } } //Output: //first error //second error //first error, second error }