fit:replace ctx err equal check as error.is (#5588)
Some checks failed
Build Test / build-linux-binary (push) Failing after -5m46s
Build / SonarCloud (push) Failing after -5m56s
sync2gitee / repo-sync (push) Failing after -5m58s

This commit is contained in:
yonwoo9 2024-06-27 17:47:10 +08:00 committed by GitHub
parent 070484772b
commit a6367fd96b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 11 additions and 10 deletions

View file

@ -3,6 +3,7 @@ package mysql
import (
"context"
"database/sql"
"errors"
"fmt"
"strings"
"time"
@ -54,7 +55,7 @@ func NewMysqlClient(conn client.DBInfo) (MysqlClient, error) {
global.LOG.Errorf("test mysql conn failed, err: %v", err)
return nil, err
}
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return nil, buserr.New(constant.ErrExecTimeOut)
}

View file

@ -350,7 +350,7 @@ func (r *Local) ExecSQL(command string, timeout uint) error {
defer cancel()
cmd := exec.CommandContext(ctx, "docker", itemCommand...)
stdout, err := cmd.CombinedOutput()
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return buserr.New(constant.ErrExecTimeOut)
}
stdStr := strings.ReplaceAll(string(stdout), "mysql: [Warning] Using a password on the command line interface can be insecure.\n", "")
@ -367,7 +367,7 @@ func (r *Local) ExecSQLForRows(command string, timeout uint) ([]string, error) {
defer cancel()
cmd := exec.CommandContext(ctx, "docker", itemCommand...)
stdout, err := cmd.CombinedOutput()
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return nil, buserr.New(constant.ErrExecTimeOut)
}
stdStr := strings.ReplaceAll(string(stdout), "mysql: [Warning] Using a password on the command line interface can be insecure.\n", "")

View file

@ -387,7 +387,7 @@ func (r *Remote) ExecSQL(command string, timeout uint) error {
if _, err := r.Client.ExecContext(ctx, command); err != nil {
return err
}
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return buserr.New(constant.ErrExecTimeOut)
}
@ -402,7 +402,7 @@ func (r *Remote) ExecSQLForHosts(timeout uint) ([]string, error) {
if err != nil {
return nil, err
}
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return nil, buserr.New(constant.ErrExecTimeOut)
}
var rows []string

View file

@ -204,7 +204,7 @@ func (r *Local) ExecSQL(command string, timeout uint) error {
defer cancel()
cmd := exec.CommandContext(ctx, "docker", itemCommand...)
stdout, err := cmd.CombinedOutput()
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return buserr.New(constant.ErrExecTimeOut)
}
if err != nil || strings.HasPrefix(string(stdout), "ERROR ") {
@ -220,7 +220,7 @@ func (r *Local) ExecSQLForRows(command string, timeout uint) ([]string, error) {
defer cancel()
cmd := exec.CommandContext(ctx, "docker", itemCommand...)
stdout, err := cmd.CombinedOutput()
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return nil, buserr.New(constant.ErrExecTimeOut)
}
if err != nil || strings.HasPrefix(string(stdout), "ERROR ") {

View file

@ -223,7 +223,7 @@ func (r *Remote) SyncDB() ([]SyncDBInfo, error) {
}
datas = append(datas, SyncDBInfo{Name: dbName, From: r.From, PostgresqlName: r.Database})
}
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return nil, buserr.New(constant.ErrExecTimeOut)
}
return datas, nil
@ -240,7 +240,7 @@ func (r *Remote) ExecSQL(command string, timeout uint) error {
if _, err := r.Client.ExecContext(ctx, command); err != nil {
return err
}
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return buserr.New(constant.ErrExecTimeOut)
}
@ -300,7 +300,7 @@ func loadImageTag() (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()
if _, err := client.ImagePull(ctx, itemTag, image.PullOptions{}); err != nil {
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return itemTag, buserr.New(constant.ErrPgImagePull)
}
global.LOG.Errorf("image %s pull failed, err: %v", itemTag, err)