From 743b41e359b9700fab73001cddbf1c40d5596251 Mon Sep 17 00:00:00 2001 From: Fedor Korotkiy Date: Wed, 11 Mar 2020 16:17:13 +0300 Subject: [PATCH] Use sentinel value --- retryupdate/kvapi/errors.go | 12 +++--------- retryupdate/update_test.go | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/retryupdate/kvapi/errors.go b/retryupdate/kvapi/errors.go index 8b0690a..0c7fea8 100644 --- a/retryupdate/kvapi/errors.go +++ b/retryupdate/kvapi/errors.go @@ -3,6 +3,7 @@ package kvapi import ( + "errors" "fmt" "github.com/gofrs/uuid" @@ -12,9 +13,10 @@ var ( _ error = (*APIError)(nil) _ error = (*ConflictError)(nil) _ error = (*AuthError)(nil) - _ error = (*NotFoundError)(nil) ) +var ErrKeyNotFound = errors.New("key not found") + type ( APIError struct { Method string @@ -29,10 +31,6 @@ type ( AuthError struct { Msg string } - - NotFoundError struct { - Key string - } ) func (a *APIError) Error() string { @@ -50,7 +48,3 @@ func (a *ConflictError) Error() string { func (a *AuthError) Error() string { return fmt.Sprintf("api: auth: %s", a.Msg) } - -func (a *NotFoundError) Error() string { - return fmt.Sprintf("api: key %q is not found", a.Key) -} diff --git a/retryupdate/update_test.go b/retryupdate/update_test.go index 9be1067..92a9357 100644 --- a/retryupdate/update_test.go +++ b/retryupdate/update_test.go @@ -31,8 +31,8 @@ var ( errGetAuth = &kvapi.APIError{Method: "get", Err: &kvapi.AuthError{Msg: "token expired"}} errSetAuth = &kvapi.APIError{Method: "set", Err: &kvapi.AuthError{Msg: "token expired"}} - errGetNoKey = &kvapi.APIError{Method: "get", Err: &kvapi.NotFoundError{Key: K0}} - errSetNoKey = &kvapi.APIError{Method: "set", Err: &kvapi.NotFoundError{Key: K0}} + errGetNoKey = &kvapi.APIError{Method: "get", Err: kvapi.ErrKeyNotFound} + errSetNoKey = &kvapi.APIError{Method: "set", Err: kvapi.ErrKeyNotFound} errGetTemporary = &kvapi.APIError{Method: "get", Err: errors.New("unavailable")} errSetTemporary = &kvapi.APIError{Method: "set", Err: errors.New("unavailable")}