diff options
author | Jordan Whited <jordan@tailscale.com> | 2023-03-16 13:27:51 -0700 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-03-17 15:18:04 +0100 |
commit | 1417a47c8fa816f427ac56ebe79a90a97a01aef5 (patch) | |
tree | 9530f2932814c081e4f1a17732221f86ca7f7e27 /tun/errors.go | |
parent | 7f511c3bb16dac4b881c4d450b61e6b2efdacc70 (diff) |
tun: replace ErrorBatch() with errors.Join()
Reviewed-by: Maisem Ali <maisem@tailscale.com>
Signed-off-by: Jordan Whited <jordan@tailscale.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tun/errors.go')
-rw-r--r-- | tun/errors.go | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/tun/errors.go b/tun/errors.go index e70b13c..75ae3a4 100644 --- a/tun/errors.go +++ b/tun/errors.go @@ -2,7 +2,6 @@ package tun import ( "errors" - "fmt" ) var ( @@ -11,50 +10,3 @@ var ( // reads to cease. ErrTooManySegments = errors.New("too many segments") ) - -type errorBatch []error - -// ErrorBatch takes a possibly nil or empty list of errors, and if the list is -// non-nil returns an error type that wraps all of the errors. Expected usage is -// to append to an []errors and coerce the set to an error using this method. -func ErrorBatch(errs []error) error { - if len(errs) == 0 { - return nil - } - return errorBatch(errs) -} - -func (e errorBatch) Error() string { - if len(e) == 0 { - return "" - } - if len(e) == 1 { - return e[0].Error() - } - return fmt.Sprintf("batch operation: %v (and %d more errors)", e[0], len(e)-1) -} - -func (e errorBatch) Is(target error) bool { - for _, err := range e { - if errors.Is(err, target) { - return true - } - } - return false -} - -func (e errorBatch) As(target interface{}) bool { - for _, err := range e { - if errors.As(err, target) { - return true - } - } - return false -} - -func (e errorBatch) Unwrap() error { - if len(e) == 0 { - return nil - } - return e[0] -} |