Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [macOS-latest, ubuntu-latest]
goversion: [1.17, 1.18, 1.19]
goversion: ['1.17', '1.18', '1.19', '1.20', '1.21', '1.22', '1.23', '1.24']
steps:

- name: Set up Go ${{matrix.goversion}} on ${{matrix.os}}
Expand Down
50 changes: 50 additions & 0 deletions errors_unwrap_go1.19_earlier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2025 Vimeo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !go1.20

package retry

import "errors"

// Unwrap returns the most recent error that occured during retrying.
func (e *Errors) Unwrap() error {
if len(e.Errs) == 0 {
return nil
}
return e.Errs[len(e.Errs)-1]
}

// Is will return true if any of the underlying errors matches the target. See
// https://golang.org/pkg/errors/#Is
func (e *Errors) Is(target error) bool {
for _, err := range e.Errs {
if errors.Is(err, target) {
return true
}
}
return false
}

// As will return true if any of the underlying errors matches the target and
// sets the argument to that error specifically. It returns false otherwise,
// leaving the argument unchanged. See https://golang.org/pkg/errors/#As
func (e *Errors) As(target interface{}) bool {
for _, err := range e.Errs {
if errors.As(err, target) {
return true
}
}
return false
}
29 changes: 29 additions & 0 deletions errors_unwrap_go1.20.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2025 Vimeo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build go1.20

package retry

// Unwrap returns the errors that occured during retrying.
func (e *Errors) Unwrap() []error {
if len(e.Errs) == 0 {
return nil
}
out := make([]error, len(e.Errs))
for i, err := range e.Errs {
out[i] = err
}
return out
}
29 changes: 0 additions & 29 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package retry

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -147,34 +146,6 @@ type Errors struct {
Errs []*Error
}

// Unwrap returns the most recent error that occured during retrying.
func (e *Errors) Unwrap() error {
return e.Errs[len(e.Errs)-1]
}

// Is will return true if any of the underlying errors matches the target. See
// https://golang.org/pkg/errors/#Is
func (e *Errors) Is(target error) bool {
for _, err := range e.Errs {
if errors.Is(err, target) {
return true
}
}
return false
}

// As will return true if any of the underlying errors matches the target and
// sets the argument to that error specifically. It returns false otherwise,
// leaving the argument unchanged. See https://golang.org/pkg/errors/#As
func (e *Errors) As(target interface{}) bool {
for _, err := range e.Errs {
if errors.As(err, target) {
return true
}
}
return false
}

// Error implements the error interface.
func (e *Errors) Error() string {
return fmt.Sprintf("errors retrying: %+v", e.Errs)
Expand Down