github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/xerrors/join.go (about)

     1  package xerrors
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring"
     7  )
     8  
     9  func Join(errs ...error) joinErrors {
    10  	return errs
    11  }
    12  
    13  type joinErrors []error
    14  
    15  func (errs joinErrors) Error() string {
    16  	b := xstring.Buffer()
    17  	defer b.Free()
    18  	b.WriteByte('[')
    19  	for i, err := range errs {
    20  		if i > 0 {
    21  			_ = b.WriteByte(',')
    22  		}
    23  		_, _ = fmt.Fprintf(b, "%q", err.Error())
    24  	}
    25  	b.WriteByte(']')
    26  
    27  	return b.String()
    28  }
    29  
    30  func (errs joinErrors) As(target interface{}) bool {
    31  	for _, err := range errs {
    32  		if As(err, target) {
    33  			return true
    34  		}
    35  	}
    36  
    37  	return false
    38  }
    39  
    40  func (errs joinErrors) Is(target error) bool {
    41  	for _, err := range errs {
    42  		if Is(err, target) {
    43  			return true
    44  		}
    45  	}
    46  
    47  	return false
    48  }
    49  
    50  func (errs joinErrors) Unwrap() []error {
    51  	return errs
    52  }