From 4c4f71e2acf855cc809201c828eb54dc067360dc Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Mon, 15 Jun 2015 11:20:28 -0700 Subject: [PATCH] Added a new RetryError to indicate the caller to possibly retry Signed-off-by: Madhu Venugopal --- libnetwork/types/types.go | 20 +++++++++++++++++++- libnetwork/types/types_test.go | 11 +++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/libnetwork/types/types.go b/libnetwork/types/types.go index 02fbcb133f..934406834b 100644 --- a/libnetwork/types/types.go +++ b/libnetwork/types/types.go @@ -228,6 +228,12 @@ type MaskableError interface { 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 type BadRequestError interface { // 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 @@ -314,6 +320,11 @@ func InternalMaskableErrorf(format string, params ...interface{}) error { 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 ***********************/ @@ -377,3 +388,10 @@ func (mnt maskInternal) Error() string { } func (mnt maskInternal) Internal() {} func (mnt maskInternal) Maskable() {} + +type retry string + +func (r retry) Error() string { + return string(r) +} +func (r retry) Retry() {} diff --git a/libnetwork/types/types_test.go b/libnetwork/types/types_test.go index 15a58e1534..efa26d7e2e 100644 --- a/libnetwork/types/types_test.go +++ b/libnetwork/types/types_test.go @@ -21,6 +21,17 @@ func TestErrorConstructors(t *testing.T) { 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") if err.Error() != "Can't find the keys" { t.Fatal(err)