[#135] Make all error status receivers pointers
All checks were successful
DCO / DCO (pull_request) Successful in 45s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m25s
Tests and linters / Tests (1.19) (pull_request) Successful in 5m54s
Tests and linters / Lint (pull_request) Successful in 6m53s

Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
Alejandro Lopez 2023-08-02 10:01:03 +03:00
parent 13d0b170d2
commit c6bac9c22b
9 changed files with 49 additions and 80 deletions

View file

@ -22,9 +22,7 @@ func IsErrContainerNotFound(err error) bool {
switch unwrapErr(err).(type) {
default:
return false
case
apistatus.ContainerNotFound,
*apistatus.ContainerNotFound:
case *apistatus.ContainerNotFound:
return true
}
}
@ -35,9 +33,7 @@ func IsErrEACLNotFound(err error) bool {
switch unwrapErr(err).(type) {
default:
return false
case
apistatus.EACLNotFound,
*apistatus.EACLNotFound:
case *apistatus.EACLNotFound:
return true
}
}
@ -48,9 +44,7 @@ func IsErrObjectNotFound(err error) bool {
switch unwrapErr(err).(type) {
default:
return false
case
apistatus.ObjectNotFound,
*apistatus.ObjectNotFound:
case *apistatus.ObjectNotFound:
return true
}
}
@ -61,9 +55,7 @@ func IsErrObjectAlreadyRemoved(err error) bool {
switch unwrapErr(err).(type) {
default:
return false
case
apistatus.ObjectAlreadyRemoved,
*apistatus.ObjectAlreadyRemoved:
case *apistatus.ObjectAlreadyRemoved:
return true
}
}
@ -74,9 +66,7 @@ func IsErrSessionExpired(err error) bool {
switch unwrapErr(err).(type) {
default:
return false
case
apistatus.SessionTokenExpired,
*apistatus.SessionTokenExpired:
case *apistatus.SessionTokenExpired:
return true
}
}
@ -87,9 +77,7 @@ func IsErrSessionNotFound(err error) bool {
switch unwrapErr(err).(type) {
default:
return false
case
apistatus.SessionTokenNotFound,
*apistatus.SessionTokenNotFound:
case *apistatus.SessionTokenNotFound:
return true
}
}

View file

@ -10,59 +10,40 @@ import (
)
func TestErrors(t *testing.T) {
for _, tc := range []struct {
errs := []struct {
check func(error) bool
errs []error
err error
}{
{
check: client.IsErrContainerNotFound,
errs: []error{
apistatus.ContainerNotFound{},
new(apistatus.ContainerNotFound),
},
err: new(apistatus.ContainerNotFound),
},
{
check: client.IsErrEACLNotFound,
errs: []error{
apistatus.EACLNotFound{},
new(apistatus.EACLNotFound),
},
err: new(apistatus.EACLNotFound),
},
{
check: client.IsErrObjectNotFound,
errs: []error{
apistatus.ObjectNotFound{},
new(apistatus.ObjectNotFound),
},
err: new(apistatus.ObjectNotFound),
},
{
check: client.IsErrObjectAlreadyRemoved,
errs: []error{
apistatus.ObjectAlreadyRemoved{},
new(apistatus.ObjectAlreadyRemoved),
},
err: new(apistatus.ObjectAlreadyRemoved),
},
{
check: client.IsErrSessionExpired,
errs: []error{
apistatus.SessionTokenExpired{},
new(apistatus.SessionTokenExpired),
},
err: new(apistatus.SessionTokenExpired),
}, {
check: client.IsErrSessionNotFound,
errs: []error{
apistatus.SessionTokenNotFound{},
new(apistatus.SessionTokenNotFound),
},
err: new(apistatus.SessionTokenNotFound),
},
} {
require.NotEmpty(t, tc.errs)
}
for i := range tc.errs {
require.True(t, tc.check(tc.errs[i]), tc.errs[i])
require.True(t, tc.check(fmt.Errorf("top-level context: :%w",
fmt.Errorf("inner context: %w", tc.errs[i])),
), tc.errs[i])
for i := range errs {
for j := range errs {
nestedErr := fmt.Errorf("top-level context: :%w", fmt.Errorf("inner context: %w", errs[j].err))
require.Equal(t, i == j, errs[i].check(errs[j].err))
require.Equal(t, i == j, errs[i].check(nestedErr))
}
}
}

View file

@ -14,7 +14,7 @@ type ServerInternal struct {
v2 status.Status
}
func (x ServerInternal) Error() string {
func (x *ServerInternal) Error() string {
return errMessageStatusV2(
globalizeCodeV2(status.Internal, status.GlobalizeCommonFail),
x.v2.Message(),
@ -62,7 +62,7 @@ type WrongMagicNumber struct {
v2 status.Status
}
func (x WrongMagicNumber) Error() string {
func (x *WrongMagicNumber) Error() string {
return errMessageStatusV2(
globalizeCodeV2(status.WrongMagicNumber, status.GlobalizeCommonFail),
x.v2.Message(),
@ -132,7 +132,7 @@ type SignatureVerification struct {
const defaultSignatureVerificationMsg = "signature verification failed"
func (x SignatureVerification) Error() string {
func (x *SignatureVerification) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultSignatureVerificationMsg
@ -191,7 +191,7 @@ type NodeUnderMaintenance struct {
const defaultNodeUnderMaintenanceMsg = "node is under maintenance"
// Error implements the error interface.
func (x NodeUnderMaintenance) Error() string {
func (x *NodeUnderMaintenance) Error() string {
msg := x.Message()
if msg == "" {
msg = defaultNodeUnderMaintenanceMsg

View file

@ -13,7 +13,7 @@ type ContainerNotFound struct {
const defaultContainerNotFoundMsg = "container not found"
func (x ContainerNotFound) Error() string {
func (x *ContainerNotFound) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultContainerNotFoundMsg
@ -51,7 +51,7 @@ type EACLNotFound struct {
const defaultEACLNotFoundMsg = "eACL not found"
func (x EACLNotFound) Error() string {
func (x *EACLNotFound) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultEACLNotFoundMsg

View file

@ -13,7 +13,7 @@ type ObjectLocked struct {
const defaultObjectLockedMsg = "object is locked"
func (x ObjectLocked) Error() string {
func (x *ObjectLocked) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultObjectLockedMsg
@ -50,7 +50,7 @@ type LockNonRegularObject struct {
const defaultLockNonRegularObjectMsg = "locking non-regular object is forbidden"
func (x LockNonRegularObject) Error() string {
func (x *LockNonRegularObject) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultLockNonRegularObjectMsg
@ -87,7 +87,7 @@ type ObjectAccessDenied struct {
const defaultObjectAccessDeniedMsg = "access to object operation denied"
func (x ObjectAccessDenied) Error() string {
func (x *ObjectAccessDenied) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultObjectAccessDeniedMsg
@ -135,7 +135,7 @@ type ObjectNotFound struct {
const defaultObjectNotFoundMsg = "object not found"
func (x ObjectNotFound) Error() string {
func (x *ObjectNotFound) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultObjectNotFoundMsg
@ -172,7 +172,7 @@ type ObjectAlreadyRemoved struct {
const defaultObjectAlreadyRemovedMsg = "object already removed"
func (x ObjectAlreadyRemoved) Error() string {
func (x *ObjectAlreadyRemoved) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultObjectAlreadyRemovedMsg
@ -210,7 +210,7 @@ type ObjectOutOfRange struct {
const defaultObjectOutOfRangeMsg = "out of range"
func (x ObjectOutOfRange) Error() string {
func (x *ObjectOutOfRange) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultObjectOutOfRangeMsg

View file

@ -13,7 +13,7 @@ type SessionTokenNotFound struct {
const defaultSessionTokenNotFoundMsg = "session token not found"
func (x SessionTokenNotFound) Error() string {
func (x *SessionTokenNotFound) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultSessionTokenNotFoundMsg
@ -50,7 +50,7 @@ type SessionTokenExpired struct {
const defaultSessionTokenExpiredMsg = "expired session token"
func (x SessionTokenExpired) Error() string {
func (x *SessionTokenExpired) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultSessionTokenExpiredMsg

View file

@ -8,7 +8,7 @@ type unrecognizedStatusV2 struct {
v2 status.Status
}
func (x unrecognizedStatusV2) Error() string {
func (x *unrecognizedStatusV2) Error() string {
return errMessageStatusV2("unrecognized", x.v2.Message())
}

View file

@ -1014,10 +1014,10 @@ func (c *clientStatusMonitor) handleError(ctx context.Context, st apistatus.Stat
err = apistatus.ErrFromStatus(st)
switch err.(type) {
case apistatus.ServerInternal, *apistatus.ServerInternal,
apistatus.WrongMagicNumber, *apistatus.WrongMagicNumber,
apistatus.SignatureVerification, *apistatus.SignatureVerification,
apistatus.NodeUnderMaintenance, *apistatus.NodeUnderMaintenance:
case *apistatus.ServerInternal,
*apistatus.WrongMagicNumber,
*apistatus.SignatureVerification,
*apistatus.NodeUnderMaintenance:
c.incErrorRate()
}

View file

@ -271,7 +271,7 @@ func TestSessionCache(t *testing.T) {
mockClientBuilder := func(addr string) client {
mockCli := newMockClient(addr, *key)
mockCli.statusOnGetObject(apistatus.SessionTokenNotFound{})
mockCli.statusOnGetObject(new(apistatus.SessionTokenNotFound))
return mockCli
}
@ -548,14 +548,14 @@ func TestHandleError(t *testing.T) {
},
{
ctx: ctx,
status: apistatus.SuccessDefaultV2{},
status: new(apistatus.SuccessDefaultV2),
err: nil,
expectedError: false,
countError: false,
},
{
ctx: ctx,
status: apistatus.SuccessDefaultV2{},
status: new(apistatus.SuccessDefaultV2),
err: errors.New("error"),
expectedError: true,
countError: true,
@ -569,42 +569,42 @@ func TestHandleError(t *testing.T) {
},
{
ctx: ctx,
status: apistatus.ObjectNotFound{},
status: new(apistatus.ObjectNotFound),
err: nil,
expectedError: true,
countError: false,
},
{
ctx: ctx,
status: apistatus.ServerInternal{},
status: new(apistatus.ServerInternal),
err: nil,
expectedError: true,
countError: true,
},
{
ctx: ctx,
status: apistatus.WrongMagicNumber{},
status: new(apistatus.WrongMagicNumber),
err: nil,
expectedError: true,
countError: true,
},
{
ctx: ctx,
status: apistatus.SignatureVerification{},
status: new(apistatus.SignatureVerification),
err: nil,
expectedError: true,
countError: true,
},
{
ctx: ctx,
status: &apistatus.SignatureVerification{},
status: new(apistatus.SignatureVerification),
err: nil,
expectedError: true,
countError: true,
},
{
ctx: ctx,
status: apistatus.NodeUnderMaintenance{},
status: new(apistatus.NodeUnderMaintenance),
err: nil,
expectedError: true,
countError: true,
@ -649,7 +649,7 @@ func TestSwitchAfterErrorThreshold(t *testing.T) {
if addr == nodes[0].address {
mockCli := newMockClient(addr, *key)
mockCli.setThreshold(uint32(errorThreshold))
mockCli.statusOnGetObject(apistatus.ServerInternal{})
mockCli.statusOnGetObject(new(apistatus.ServerInternal))
return mockCli
}