Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fserrors: fix a bug in Cause function

Cenk Alti58f280b8a2a2
diff --git a/fs/fserrors/error.go b/fs/fserrors/error.go
index eb6d7055d..aef83fe35 100644
--- a/fs/fserrors/error.go
+++ b/fs/fserrors/error.go
@@ -236,14 +236,14 @@ func IsRetryAfterError(err error) bool {
func Cause(cause error) (retriable bool, err error) {
errors.Walk(cause, func(c error) bool {
// Check for net error Timeout()
- if x, ok := err.(interface {
+ if x, ok := c.(interface {
Timeout() bool
}); ok && x.Timeout() {
retriable = true
}
// Check for net error Temporary()
- if x, ok := err.(interface {
+ if x, ok := c.(interface {
Temporary() bool
}); ok && x.Temporary() {
retriable = true
diff --git a/fs/fserrors/error_test.go b/fs/fserrors/error_test.go
index 93ffcaa67..f153c7aab 100644
--- a/fs/fserrors/error_test.go
+++ b/fs/fserrors/error_test.go
@@ -62,6 +62,12 @@ type myError4 struct {
func (e *myError4) Error() string { return e.e.Error() }
+type myError5 struct{}
+
+func (e *myError5) Error() string { return "" }
+
+func (e *myError5) Temporary() bool { return true }
+
type errorCause struct {
e error
}
@@ -73,6 +79,7 @@ func (e *errorCause) Cause() error { return e.e }
func TestCause(t *testing.T) {
e3 := &myError3{3}
e4 := &myError4{io.EOF}
+ e5 := &myError5{}
eNil1 := &myError2{nil}
eNil2 := &myError2{Err: (*myError2)(nil)}
errPotato := errors.New("potato")
@@ -97,6 +104,7 @@ func TestCause(t *testing.T) {
{&myError2{io.EOF}, false, io.EOF},
{e3, false, e3},
{e4, false, e4},
+ {e5, true, e5},
{&errorCause{errPotato}, false, errPotato},
{nilCause1, false, nilCause1},
{nilCause2, false, nilCause2.e},