refactor: replace deprecated github.com/pkg/errors with errors pkg (#5577)
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Command is an experimental interface
|
||||
|
||||
@@ -20,8 +20,6 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
)
|
||||
|
||||
@@ -92,9 +90,8 @@ func (t *TagAutoWireBeanFactory) AutoWire(ctx context.Context, appCtx Applicatio
|
||||
switch fValue.Kind() {
|
||||
case reflect.Bool:
|
||||
if v, err := strconv.ParseBool(fm.DftValue); err != nil {
|
||||
return errors.WithMessage(err,
|
||||
fmt.Sprintf("can not convert the field[%s]'s default value[%s] to bool value",
|
||||
fn, fm.DftValue))
|
||||
return fmt.Errorf("can not convert the field[%s]'s default value[%s] to bool value: %w",
|
||||
fn, fm.DftValue, err)
|
||||
} else {
|
||||
fValue.SetBool(v)
|
||||
continue
|
||||
@@ -182,9 +179,8 @@ func (t *TagAutoWireBeanFactory) AutoWire(ctx context.Context, appCtx Applicatio
|
||||
|
||||
func (t *TagAutoWireBeanFactory) setFloatXValue(dftValue string, bitSize int, fn string, fv reflect.Value) error {
|
||||
if v, err := strconv.ParseFloat(dftValue, bitSize); err != nil {
|
||||
return errors.WithMessage(err,
|
||||
fmt.Sprintf("can not convert the field[%s]'s default value[%s] to float%d value",
|
||||
fn, dftValue, bitSize))
|
||||
return fmt.Errorf("can not convert the field[%s]'s default value[%s] to float%d value: %w",
|
||||
fn, dftValue, bitSize, err)
|
||||
} else {
|
||||
fv.SetFloat(v)
|
||||
return nil
|
||||
@@ -193,9 +189,8 @@ func (t *TagAutoWireBeanFactory) setFloatXValue(dftValue string, bitSize int, fn
|
||||
|
||||
func (t *TagAutoWireBeanFactory) setUIntXValue(dftValue string, bitSize int, fn string, fv reflect.Value) error {
|
||||
if v, err := strconv.ParseUint(dftValue, 10, bitSize); err != nil {
|
||||
return errors.WithMessage(err,
|
||||
fmt.Sprintf("can not convert the field[%s]'s default value[%s] to uint%d value",
|
||||
fn, dftValue, bitSize))
|
||||
return fmt.Errorf("can not convert the field[%s]'s default value[%s] to uint%d value: %w",
|
||||
fn, dftValue, bitSize, err)
|
||||
} else {
|
||||
fv.SetUint(v)
|
||||
return nil
|
||||
@@ -204,9 +199,8 @@ func (t *TagAutoWireBeanFactory) setUIntXValue(dftValue string, bitSize int, fn
|
||||
|
||||
func (t *TagAutoWireBeanFactory) setIntXValue(dftValue string, bitSize int, fn string, fv reflect.Value) error {
|
||||
if v, err := strconv.ParseInt(dftValue, 10, bitSize); err != nil {
|
||||
return errors.WithMessage(err,
|
||||
fmt.Sprintf("can not convert the field[%s]'s default value[%s] to int%d value",
|
||||
fn, dftValue, bitSize))
|
||||
return fmt.Errorf("can not convert the field[%s]'s default value[%s] to int%d value: %w",
|
||||
fn, dftValue, bitSize, err)
|
||||
} else {
|
||||
fv.SetInt(v)
|
||||
return nil
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// code, msg
|
||||
@@ -39,7 +37,7 @@ func Wrap(err error, c Code, msg string) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, fmt.Sprintf(errFmt, c.Code(), msg))
|
||||
return fmt.Errorf(errFmt+": %w", c.Code(), msg, err)
|
||||
}
|
||||
|
||||
func Wrapf(err error, c Code, format string, a ...interface{}) error {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// now not all implementation return those error codes
|
||||
|
||||
@@ -17,12 +17,12 @@ package etcd
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/pkg/errors"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
@@ -82,7 +82,7 @@ func (e *EtcdConfiger) GetSection(section string) (map[string]string, error) {
|
||||
resp, err = e.client.Get(context.TODO(), e.prefix+section, clientv3.WithPrefix())
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "GetSection failed")
|
||||
return nil, fmt.Errorf("GetSection failed: %w", err)
|
||||
}
|
||||
res := make(map[string]string, len(resp.Kvs))
|
||||
for _, kv := range resp.Kvs {
|
||||
@@ -101,7 +101,7 @@ func (e *EtcdConfiger) SaveConfigFile(filename string) error {
|
||||
func (e *EtcdConfiger) Unmarshaler(prefix string, obj interface{}, opt ...config.DecodeOption) error {
|
||||
res, err := e.GetSection(prefix)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, fmt.Sprintf("could not read config with prefix: %s", prefix))
|
||||
return fmt.Errorf("could not read config with prefix: %s: %w", prefix, err)
|
||||
}
|
||||
|
||||
prefixLen := len(e.prefix + prefix)
|
||||
@@ -158,7 +158,7 @@ func (provider *EtcdConfigerProvider) ParseData(data []byte) (config.Configer, e
|
||||
cfg := &clientv3.Config{}
|
||||
err := json.Unmarshal(data, cfg)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "parse data to etcd config failed, please check your input")
|
||||
return nil, fmt.Errorf("parse data to etcd config failed, please check your input: %w", err)
|
||||
}
|
||||
|
||||
cfg.DialOptions = []grpc.DialOption{
|
||||
@@ -168,7 +168,7 @@ func (provider *EtcdConfigerProvider) ParseData(data []byte) (config.Configer, e
|
||||
}
|
||||
client, err := clientv3.New(*cfg)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "create etcd client failed")
|
||||
return nil, fmt.Errorf("create etcd client failed: %w", err)
|
||||
}
|
||||
|
||||
return newEtcdConfiger(client, ""), nil
|
||||
@@ -182,7 +182,7 @@ func get(client *clientv3.Client, key string) (*clientv3.GetResponse, error) {
|
||||
resp, err = client.Get(context.Background(), key)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, fmt.Sprintf("read config from etcd with key %s failed", key))
|
||||
return nil, fmt.Errorf("read config from etcd with key %s failed: %w", key, err)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
)
|
||||
@@ -110,7 +109,7 @@ func (c *aliLSWriter) Init(config string) error {
|
||||
if len(c.Formatter) > 0 {
|
||||
fmtr, ok := logs.GetFormatter(c.Formatter)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("the formatter with name: %s not found", c.Formatter))
|
||||
return fmt.Errorf("the formatter with name: %s not found", c.Formatter)
|
||||
}
|
||||
c.formatter = fmtr
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// connWriter implements LoggerInterface.
|
||||
@@ -56,7 +54,7 @@ func (c *connWriter) Init(config string) error {
|
||||
if res == nil && len(c.Formatter) > 0 {
|
||||
fmtr, ok := GetFormatter(c.Formatter)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("the formatter with name: %s not found", c.Formatter))
|
||||
return fmt.Errorf("the formatter with name: %s not found", c.Formatter)
|
||||
}
|
||||
c.formatter = fmtr
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/shiena/ansicolor"
|
||||
)
|
||||
|
||||
@@ -95,7 +94,7 @@ func (c *consoleWriter) Init(config string) error {
|
||||
if res == nil && len(c.Formatter) > 0 {
|
||||
fmtr, ok := GetFormatter(c.Formatter)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("the formatter with name: %s not found", c.Formatter))
|
||||
return fmt.Errorf("the formatter with name: %s not found", c.Formatter)
|
||||
}
|
||||
c.formatter = fmtr
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// JLWriter implements beego LoggerInterface and is used to send jiaoliao webhook
|
||||
@@ -35,7 +33,7 @@ func (s *JLWriter) Init(config string) error {
|
||||
if res == nil && len(s.Formatter) > 0 {
|
||||
fmtr, ok := GetFormatter(s.Formatter)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("the formatter with name: %s not found", s.Formatter))
|
||||
return fmt.Errorf("the formatter with name: %s not found", s.Formatter)
|
||||
}
|
||||
s.formatter = fmtr
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// SLACKWriter implements beego LoggerInterface and is used to send jiaoliao webhook
|
||||
@@ -40,7 +38,7 @@ func (s *SLACKWriter) Init(config string) error {
|
||||
if res == nil && len(s.Formatter) > 0 {
|
||||
fmtr, ok := GetFormatter(s.Formatter)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("the formatter with name: %s not found", s.Formatter))
|
||||
return fmt.Errorf("the formatter with name: %s not found", s.Formatter)
|
||||
}
|
||||
s.formatter = fmtr
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ import (
|
||||
"net"
|
||||
"net/smtp"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// SMTPWriter implements LoggerInterface and is used to send emails via given SMTP-server.
|
||||
@@ -62,7 +60,7 @@ func (s *SMTPWriter) Init(config string) error {
|
||||
if res == nil && len(s.Formatter) > 0 {
|
||||
fmtr, ok := GetFormatter(s.Formatter)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("the formatter with name: %s not found", s.Formatter))
|
||||
return fmt.Errorf("the formatter with name: %s not found", s.Formatter)
|
||||
}
|
||||
s.formatter = fmtr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user