mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 12:05:05 +08:00
fserrors: fix a bug in Cause function
This commit is contained in:
parent
ec09de1628
commit
58f280b8a2
|
@ -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
|
||||
|
|
|
@ -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},
|
||||
|
|
Loading…
Reference in New Issue
Block a user