Skip to content

Commit 4c4f71e

Browse files
mavenugoaboch
authored andcommitted
Added a new RetryError to indicate the caller to possibly retry
Signed-off-by: Madhu Venugopal <madhu@docker.com>
1 parent 883fc7b commit 4c4f71e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

libnetwork/types/types.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ type MaskableError interface {
228228
Maskable()
229229
}
230230

231+
// RetryError is an interface for errors which might get resolved through retry
232+
type RetryError interface {
233+
// Retry makes implementer into RetryError type
234+
Retry()
235+
}
236+
231237
// BadRequestError is an interface for errors originated by a bad request
232238
type BadRequestError interface {
233239
// BadRequest makes implementer into BadRequestError type
@@ -271,7 +277,7 @@ type InternalError interface {
271277
}
272278

273279
/******************************
274-
* Weel-known Error Formatters
280+
* Well-known Error Formatters
275281
******************************/
276282

277283
// BadRequestErrorf creates an instance of BadRequestError
@@ -314,6 +320,11 @@ func InternalMaskableErrorf(format string, params ...interface{}) error {
314320
return maskInternal(fmt.Sprintf(format, params...))
315321
}
316322

323+
// RetryErrorf creates an instance of RetryError
324+
func RetryErrorf(format string, params ...interface{}) error {
325+
return retry(fmt.Sprintf(format, params...))
326+
}
327+
317328
/***********************
318329
* Internal Error Types
319330
***********************/
@@ -377,3 +388,10 @@ func (mnt maskInternal) Error() string {
377388
}
378389
func (mnt maskInternal) Internal() {}
379390
func (mnt maskInternal) Maskable() {}
391+
392+
type retry string
393+
394+
func (r retry) Error() string {
395+
return string(r)
396+
}
397+
func (r retry) Retry() {}

libnetwork/types/types_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ func TestErrorConstructors(t *testing.T) {
2121
t.Fatal(err)
2222
}
2323

24+
err = RetryErrorf("Incy wincy %s went up the spout again", "spider")
25+
if err.Error() != "Incy wincy spider went up the spout again" {
26+
t.Fatal(err)
27+
}
28+
if _, ok := err.(RetryError); !ok {
29+
t.Fatal(err)
30+
}
31+
if _, ok := err.(MaskableError); ok {
32+
t.Fatal(err)
33+
}
34+
2435
err = NotFoundErrorf("Can't find the %s", "keys")
2536
if err.Error() != "Can't find the keys" {
2637
t.Fatal(err)

0 commit comments

Comments
 (0)