Selaa lähdekoodia

Added a new RetryError to indicate the caller to possibly retry

Signed-off-by: Madhu Venugopal <madhu@docker.com>
Madhu Venugopal 10 vuotta sitten
vanhempi
commit
4c4f71e2ac
2 muutettua tiedostoa jossa 30 lisäystä ja 1 poistoa
  1. 19 1
      libnetwork/types/types.go
  2. 11 0
      libnetwork/types/types_test.go

+ 19 - 1
libnetwork/types/types.go

@@ -228,6 +228,12 @@ type MaskableError interface {
 	Maskable()
 	Maskable()
 }
 }
 
 
+// RetryError is an interface for errors which might get resolved through retry
+type RetryError interface {
+	// Retry makes implementer into RetryError type
+	Retry()
+}
+
 // BadRequestError is an interface for errors originated by a bad request
 // BadRequestError is an interface for errors originated by a bad request
 type BadRequestError interface {
 type BadRequestError interface {
 	// BadRequest makes implementer into BadRequestError type
 	// BadRequest makes implementer into BadRequestError type
@@ -271,7 +277,7 @@ type InternalError interface {
 }
 }
 
 
 /******************************
 /******************************
- * Weel-known Error Formatters
+ * Well-known Error Formatters
  ******************************/
  ******************************/
 
 
 // BadRequestErrorf creates an instance of BadRequestError
 // BadRequestErrorf creates an instance of BadRequestError
@@ -314,6 +320,11 @@ func InternalMaskableErrorf(format string, params ...interface{}) error {
 	return maskInternal(fmt.Sprintf(format, params...))
 	return maskInternal(fmt.Sprintf(format, params...))
 }
 }
 
 
+// RetryErrorf creates an instance of RetryError
+func RetryErrorf(format string, params ...interface{}) error {
+	return retry(fmt.Sprintf(format, params...))
+}
+
 /***********************
 /***********************
  * Internal Error Types
  * Internal Error Types
  ***********************/
  ***********************/
@@ -377,3 +388,10 @@ func (mnt maskInternal) Error() string {
 }
 }
 func (mnt maskInternal) Internal() {}
 func (mnt maskInternal) Internal() {}
 func (mnt maskInternal) Maskable() {}
 func (mnt maskInternal) Maskable() {}
+
+type retry string
+
+func (r retry) Error() string {
+	return string(r)
+}
+func (r retry) Retry() {}

+ 11 - 0
libnetwork/types/types_test.go

@@ -21,6 +21,17 @@ func TestErrorConstructors(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
+	err = RetryErrorf("Incy wincy %s went up the spout again", "spider")
+	if err.Error() != "Incy wincy spider went up the spout again" {
+		t.Fatal(err)
+	}
+	if _, ok := err.(RetryError); !ok {
+		t.Fatal(err)
+	}
+	if _, ok := err.(MaskableError); ok {
+		t.Fatal(err)
+	}
+
 	err = NotFoundErrorf("Can't find the %s", "keys")
 	err = NotFoundErrorf("Can't find the %s", "keys")
 	if err.Error() != "Can't find the keys" {
 	if err.Error() != "Can't find the keys" {
 		t.Fatal(err)
 		t.Fatal(err)