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
12 changes: 3 additions & 9 deletions agent/exec/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,9 @@ func (t temporary) Temporary() bool { return true }
// IsTemporary returns true if the error or a recursive cause returns true for
// temporary.
func IsTemporary(err error) bool {
if tmp, ok := err.(Temporary); ok && tmp.Temporary() {
return true
var tmp Temporary
if errors.As(err, &tmp) {
return tmp.Temporary()
}

cause := errors.Cause(err)

if tmp, ok := cause.(Temporary); ok && tmp.Temporary() {
return true
}

return false
}
27 changes: 27 additions & 0 deletions agent/exec/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package exec

import (
"fmt"
"testing"

"github.com/pkg/errors"
)

func TestIsTemporary(t *testing.T) {
err := fmt.Errorf("err")
err1 := MakeTemporary(fmt.Errorf("err1: %w", err))
err2 := fmt.Errorf("err2: %w", err1)
err3 := errors.Wrap(err2, "err3")
err4 := fmt.Errorf("err4: %w", err3)
err5 := errors.Wrap(err4, "err5")

if IsTemporary(nil) {
t.Error("expected error to not be a temporary error")
}
if IsTemporary(err) {
t.Error("expected error to not be a temporary error")
}
if !IsTemporary(err5) {
t.Error("expected error to be a temporary error")
}
}