mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2024-12-05 21:38:26 +08:00
fit:replace ctx err equal check as error.is (#5588)
This commit is contained in:
parent
070484772b
commit
a6367fd96b
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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", "")
|
||||
|
@ -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
|
||||
|
@ -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 ") {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user