Skip to content

Commit

Permalink
policer: Use errors.Is to check status error instead of manual casts
Browse files Browse the repository at this point in the history
NeoFS SDK is full friendly with Go std error system used in `errors`
package.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Feb 27, 2024
1 parent a4900da commit ac5b722
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions pkg/services/policer/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (p *Policer) processNodes(ctx *processPlacementContext, nodes []netmap.Node
continue
}

if isClientErrMaintenance(err) {
if errors.Is(err, apistatus.ErrNodeUnderMaintenance) {

Check warning on line 280 in pkg/services/policer/check.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/policer/check.go#L280

Added line #L280 was not covered by tests
handleMaintenance(nodes[i])
} else if err != nil {
p.log.Error("receive object header to check policy compliance",
Expand Down Expand Up @@ -314,28 +314,3 @@ func (p *Policer) processNodes(ctx *processPlacementContext, nodes []netmap.Node
zap.Int("count", uncheckedCopies))
}
}

// isClientErrMaintenance checks if err corresponds to NeoFS status return
// which tells that node is currently under maintenance. Supports wrapped
// errors.
//
// Similar to client.IsErr___ errors, consider replacing to NeoFS SDK.
func isClientErrMaintenance(err error) bool {
switch unwrapErr(err).(type) {
default:
return false
case
apistatus.NodeUnderMaintenance,
*apistatus.NodeUnderMaintenance:
return true
}
}

// unwrapErr unwraps error using errors.Unwrap.
func unwrapErr(err error) error {
for e := errors.Unwrap(err); e != nil; e = errors.Unwrap(err) {
err = e
}

return err
}

0 comments on commit ac5b722

Please sign in to comment.