Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: change err == xx to errors.Is(err, xx) #3991

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/iox/textlinescanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package iox

import (
"bufio"
"errors"
"io"
"strings"
)
Expand Down Expand Up @@ -30,7 +31,7 @@ func (scanner *TextLineScanner) Scan() bool {

line, err := scanner.reader.ReadString('\n')
scanner.line = strings.TrimRight(line, "\n")
if err == io.EOF {
if errors.Is(err, io.EOF) {
scanner.hasNext = false
return true
} else if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/stores/redis/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func formatError(err error) string {
}

switch {
case err == io.EOF:
case errors.Is(err, io.EOF):
return "eof"
case errors.Is(err, context.DeadlineExceeded):
return "context deadline"
Expand Down
3 changes: 2 additions & 1 deletion tools/goctl/rpc/generator/genpb.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package generator

import (
"errors"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -86,7 +87,7 @@ func findPbFile(current string, src string, grpc bool) (string, error) {
}
return nil
})
if err == os.ErrExist {
if errors.Is(err, os.ErrExist) {
return filepath.Dir(filepath.Join(current, ret)), nil
}
return "", err
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/util/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func split(content string) ([]string, error) {
for {
r, _, err := reader.ReadRune()
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
if buffer.Len() > 0 {
list = append(list, buffer.String())
}
Expand Down
3 changes: 2 additions & 1 deletion zrpc/internal/clientinterceptors/tracinginterceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clientinterceptors

import (
"context"
"errors"
"io"

ztrace "github.com/zeromicro/go-zero/core/trace"
Expand Down Expand Up @@ -122,7 +123,7 @@ func (w *clientStream) RecvMsg(m any) error {
err := w.ClientStream.RecvMsg(m)
if err == nil && !w.desc.ServerStreams {
w.sendStreamEvent(receiveEndEvent, nil)
} else if err == io.EOF {
} else if errors.Is(err, io.EOF) {
w.sendStreamEvent(receiveEndEvent, nil)
} else if err != nil {
w.sendStreamEvent(errorEvent, err)
Expand Down