1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Added a new RetryError to indicate the caller to possibly retry

Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2015-06-15 11:20:28 -07:00 committed by Alessandro Boch
parent 883fc7bca4
commit 4c4f71e2ac
2 changed files with 30 additions and 1 deletions

View file

@ -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() {}

View file

@ -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)