Skip to content

Commit

Permalink
server: remaining errors.Is conversions for error equality and inequa…
Browse files Browse the repository at this point in the history
…lity checks

Signed-off-by: redwrasse <[email protected]>
  • Loading branch information
redwrasse committed Sep 24, 2024
1 parent bd93a00 commit 500b853
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/etcdserver/api/v3rpc/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (ls *LeaseServer) LeaseTimeToLive(ctx context.Context, rr *pb.LeaseTimeToLi

func (ls *LeaseServer) LeaseLeases(ctx context.Context, rr *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) {
resp, err := ls.le.LeaseLeases(ctx, rr)
if err != nil && err != lease.ErrLeaseNotFound {
if err != nil && !errors.Is(err, lease.ErrLeaseNotFound) {
return nil, togRPCError(err)
}
if err == lease.ErrLeaseNotFound {
Expand Down
3 changes: 2 additions & 1 deletion server/etcdserver/api/v3rpc/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v3rpc
import (
"context"
"crypto/sha256"
errorspkg "errors"
"io"
"time"

Expand Down Expand Up @@ -163,7 +164,7 @@ func (ms *maintenanceServer) Snapshot(sr *pb.SnapshotRequest, srv pb.Maintenance
buf := make([]byte, snapshotSendBufferSize)

n, err := io.ReadFull(pr, buf)
if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
if err != nil && err != io.EOF && !errorspkg.Is(err, io.ErrUnexpectedEOF) {
return togRPCError(err)
}
sent += int64(n)
Expand Down
3 changes: 2 additions & 1 deletion server/etcdserver/apply/uber_applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package apply

import (
"context"
"errors"
"time"

"go.uber.org/zap"
Expand Down Expand Up @@ -123,7 +124,7 @@ func (a *uberApplier) dispatch(ctx context.Context, r *pb.InternalRaftRequest) *
op := "unknown"
ar := &Result{}
defer func(start time.Time) {
success := ar.Err == nil || ar.Err == mvcc.ErrCompacted
success := ar.Err == nil || errors.Is(ar.Err, mvcc.ErrCompacted)
txn.ApplySecObserve(v3Version, op, success, time.Since(start))
txn.WarnOfExpensiveRequest(a.lg, a.warningApplyDuration, start, &pb.InternalRaftStringer{Request: r}, ar.Resp, ar.Err)
if !success {
Expand Down
3 changes: 2 additions & 1 deletion server/proxy/grpcproxy/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package grpcproxy

import (
"context"
"errors"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -52,7 +53,7 @@ func checkHealth(c *clientv3.Client) etcdhttp.Health {
ctx, cancel := context.WithTimeout(c.Ctx(), time.Second)
_, err := c.Get(ctx, "a")
cancel()
if err == nil || err == rpctypes.ErrPermissionDenied {
if err == nil || errors.Is(err, rpctypes.ErrPermissionDenied) {
h.Health = "true"
} else {
h.Reason = fmt.Sprintf("GET ERROR:%s", err)
Expand Down
3 changes: 2 additions & 1 deletion server/storage/backend/batch_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package backend

import (
"bytes"
"errors"
"math"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -125,7 +126,7 @@ func (t *batchTx) UnsafeCreateBucket(bucket Bucket) {

func (t *batchTx) UnsafeDeleteBucket(bucket Bucket) {
err := t.tx.DeleteBucket(bucket.Name())
if err != nil && err != bolterrors.ErrBucketNotFound {
if err != nil && !errors.Is(err, bolterrors.ErrBucketNotFound) {
t.backend.lg.Fatal(
"failed to delete a bucket",
zap.Stringer("bucket-name", bucket),
Expand Down
3 changes: 2 additions & 1 deletion server/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package storage

import (
"errors"
"sync"

"github.com/coreos/go-semver/semver"
Expand Down Expand Up @@ -112,7 +113,7 @@ func (st *storage) MinimalEtcdVersion() *semver.Version {
walsnap := walpb.Snapshot{}

sn, err := st.s.Load()
if err != nil && err != snap.ErrNoSnapshot {
if err != nil && !errors.Is(err, snap.ErrNoSnapshot) {
panic(err)
}
if sn != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/storage/wal/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ func TestOpenOnTornWrite(t *testing.T) {
p := t.TempDir()
w, err := Create(zaptest.NewLogger(t), p, nil)
defer func() {
if err = w.Close(); err != nil && err != os.ErrInvalid {
if err = w.Close(); err != nil && !errors.Is(os.ErrInvalid, err) {
t.Fatal(err)
}
}()
Expand Down

0 comments on commit 500b853

Please sign in to comment.