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

alias github.com/pkg/errors to pkgerrors #11848

Merged
merged 20 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions charts/chainlink-cluster/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/K-Phoen/grabana/timeseries"
"github.com/K-Phoen/grabana/timeseries/axis"
"github.com/K-Phoen/grabana/variable/query"
"github.com/pkg/errors"
pkgerrors "github.com/pkg/errors"
)

/*
Expand Down Expand Up @@ -954,10 +954,10 @@ func (m *CLClusterDashboard) Deploy(ctx context.Context) error {
client := grabana.NewClient(&http.Client{}, m.GrafanaURL, grabana.WithAPIToken(m.GrafanaToken))
folder, err := client.FindOrCreateFolder(ctx, m.Folder)
if err != nil {
return errors.Wrap(err, ErrFailedToCreateFolder)
return pkgerrors.Wrap(err, ErrFailedToCreateFolder)
}
if _, err := client.UpsertDashboard(ctx, folder, m.builder); err != nil {
return errors.Wrap(err, ErrFailedToCreateDashboard)
return pkgerrors.Wrap(err, ErrFailedToCreateDashboard)
}
return nil
}
7 changes: 4 additions & 3 deletions core/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import (
"encoding/hex"
"fmt"

pkgerrors "github.com/pkg/errors"

"github.com/smartcontractkit/chainlink/v2/core/utils"

"github.com/pkg/errors"
"golang.org/x/crypto/sha3"
)

var (
// ErrorAuthFailed is a generic authentication failed - but not because of
// some system failure on our behalf (i.e. HTTP 5xx), more detail is not
// given
ErrorAuthFailed = errors.New("Authentication failed")
ErrorAuthFailed = pkgerrors.New("Authentication failed")
)

// Token is used for API authentication.
Expand Down Expand Up @@ -57,7 +58,7 @@ func HashedSecret(ta *Token, salt string) (string, error) {
hasher := sha3.New256()
_, err := hasher.Write(hashInput(ta, salt))
if err != nil {
return "", errors.Wrap(err, "error writing external initiator authentication to hasher")
return "", pkgerrors.Wrap(err, "error writing external initiator authentication to hasher")
}
return hex.EncodeToString(hasher.Sum(nil)), nil
}
6 changes: 3 additions & 3 deletions core/bridges/external_initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"strings"
"time"

pkgerrors "github.com/pkg/errors"

"github.com/smartcontractkit/chainlink/v2/core/auth"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
"github.com/smartcontractkit/chainlink/v2/core/utils"

"github.com/pkg/errors"
)

// ExternalInitiatorRequest is the incoming record used to create an ExternalInitiator.
Expand Down Expand Up @@ -42,7 +42,7 @@ func NewExternalInitiator(
salt := utils.NewSecret(utils.DefaultSecretSize)
hashedSecret, err := auth.HashedSecret(eia, salt)
if err != nil {
return nil, errors.Wrap(err, "error hashing secret for external initiator")
return nil, pkgerrors.Wrap(err, "error hashing secret for external initiator")
}

return &ExternalInitiator{
Expand Down
26 changes: 13 additions & 13 deletions core/bridges/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
pkgerrors "github.com/pkg/errors"

"github.com/smartcontractkit/chainlink/v2/core/auth"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down Expand Up @@ -67,7 +67,7 @@ func (o *orm) FindBridge(name BridgeName) (bt BridgeType, err error) {
// Expects all bridges to be unique
func (o *orm) FindBridges(names []BridgeName) (bts []BridgeType, err error) {
if len(names) == 0 {
return nil, errors.Errorf("at least one bridge name is required")
return nil, pkgerrors.Errorf("at least one bridge name is required")
}

var allFoundBts []BridgeType
Expand Down Expand Up @@ -99,7 +99,7 @@ func (o *orm) FindBridges(names []BridgeName) (bts []BridgeType, err error) {
}
allFoundBts = append(allFoundBts, bts...)
if len(allFoundBts) != len(names) {
return nil, errors.Errorf("not all bridges exist, asked for %v, exists %v", names, allFoundBts)
return nil, pkgerrors.Errorf("not all bridges exist, asked for %v, exists %v", names, allFoundBts)
}
return allFoundBts, nil
}
Expand Down Expand Up @@ -128,11 +128,11 @@ func (o *orm) DeleteBridgeType(bt *BridgeType) error {
func (o *orm) BridgeTypes(offset int, limit int) (bridges []BridgeType, count int, err error) {
err = o.q.Transaction(func(tx pg.Queryer) error {
if err = tx.Get(&count, "SELECT COUNT(*) FROM bridge_types"); err != nil {
return errors.Wrap(err, "BridgeTypes failed to get count")
return pkgerrors.Wrap(err, "BridgeTypes failed to get count")
}
sql := `SELECT * FROM bridge_types ORDER BY name asc LIMIT $1 OFFSET $2;`
if err = tx.Select(&bridges, sql, limit, offset); err != nil {
return errors.Wrap(err, "BridgeTypes failed to load bridge_types")
return pkgerrors.Wrap(err, "BridgeTypes failed to load bridge_types")
}
return nil
}, pg.OptReadOnlyTx())
Expand All @@ -157,7 +157,7 @@ func (o *orm) CreateBridgeType(bt *BridgeType) error {
o.bridgeTypesCache.Store(bt.Name, *bt)
}

return errors.Wrap(err, "CreateBridgeType failed")
return pkgerrors.Wrap(err, "CreateBridgeType failed")
}

// UpdateBridgeType updates the bridge type.
Expand All @@ -179,7 +179,7 @@ func (o *orm) GetCachedResponse(dotId string, specId int32, maxElapsed time.Dura
finished_at > ($3)
ORDER BY finished_at
DESC LIMIT 1;`
err = errors.Wrap(o.q.Get(&response, sql, dotId, specId, stalenessThreshold), fmt.Sprintf("failed to fetch last good value for task %s spec %d", dotId, specId))
err = pkgerrors.Wrap(o.q.Get(&response, sql, dotId, specId, stalenessThreshold), fmt.Sprintf("failed to fetch last good value for task %s spec %d", dotId, specId))
return
}

Expand All @@ -190,7 +190,7 @@ func (o *orm) UpsertBridgeResponse(dotId string, specId int32, response []byte)
DO UPDATE SET value = $3, finished_at = $4;`

err := o.q.ExecQ(sql, dotId, specId, response, time.Now())
return errors.Wrap(err, "failed to upsert bridge response")
return pkgerrors.Wrap(err, "failed to upsert bridge response")
}

// --- External Initiator
Expand All @@ -199,12 +199,12 @@ func (o *orm) UpsertBridgeResponse(dotId string, specId int32, response []byte)
func (o *orm) ExternalInitiators(offset int, limit int) (exis []ExternalInitiator, count int, err error) {
err = o.q.Transaction(func(tx pg.Queryer) error {
if err = tx.Get(&count, "SELECT COUNT(*) FROM external_initiators"); err != nil {
return errors.Wrap(err, "ExternalInitiators failed to get count")
return pkgerrors.Wrap(err, "ExternalInitiators failed to get count")
}

sql := `SELECT * FROM external_initiators ORDER BY name asc LIMIT $1 OFFSET $2;`
if err = tx.Select(&exis, sql, limit, offset); err != nil {
return errors.Wrap(err, "ExternalInitiators failed to load external_initiators")
return pkgerrors.Wrap(err, "ExternalInitiators failed to load external_initiators")
}
return nil
}, pg.OptReadOnlyTx())
Expand All @@ -221,12 +221,12 @@ func (o *orm) CreateExternalInitiator(externalInitiator *ExternalInitiator) (err
var stmt *sqlx.NamedStmt
stmt, err = tx.PrepareNamed(query)
if err != nil {
return errors.Wrap(err, "failed to prepare named stmt")
return pkgerrors.Wrap(err, "failed to prepare named stmt")
}
defer stmt.Close()
return errors.Wrap(stmt.Get(externalInitiator, externalInitiator), "failed to load external_initiator")
return pkgerrors.Wrap(stmt.Get(externalInitiator, externalInitiator), "failed to load external_initiator")
})
return errors.Wrap(err, "CreateExternalInitiator failed")
return pkgerrors.Wrap(err, "CreateExternalInitiator failed")
}

// DeleteExternalInitiator removes an external initiator
Expand Down
4 changes: 2 additions & 2 deletions core/cbor/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/big"

"github.com/fxamacker/cbor/v2"
"github.com/pkg/errors"
pkgerrors "github.com/pkg/errors"
)

// ParseDietCBOR attempts to coerce the input byte array into valid CBOR.
Expand All @@ -28,7 +28,7 @@ func ParseDietCBOR(b []byte) (map[string]interface{}, error) {

output, ok := coerced.(map[string]interface{})
if !ok {
return nil, errors.New("cbor data cannot be coerced to map")
return nil, pkgerrors.New("cbor data cannot be coerced to map")
}

return output, nil
Expand Down
12 changes: 6 additions & 6 deletions core/chains/evm/assets/wei.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/big"
"strings"

"github.com/pkg/errors"
pkgerrors "github.com/pkg/errors"
"github.com/shopspring/decimal"
"golang.org/x/exp/constraints"

Expand Down Expand Up @@ -185,7 +185,7 @@ func (w *Wei) UnmarshalText(b []byte) error {
t = strings.TrimSuffix(t, " ")
d, err := decimal.NewFromString(t)
if err != nil {
return errors.Wrapf(err, "unable to parse %q", s)
return pkgerrors.Wrapf(err, "unable to parse %q", s)
}
se := suffixExp(suf)
if d.IsInteger() {
Expand All @@ -196,8 +196,8 @@ func (w *Wei) UnmarshalText(b []byte) error {

d = d.Mul(decimal.New(1, se))
if !d.IsInteger() {
err := errors.New("maximum precision is wei")
return errors.Wrapf(err, "unable to parse %q", s)
err := pkgerrors.New("maximum precision is wei")
return pkgerrors.Wrapf(err, "unable to parse %q", s)
}
*w = (Wei)(*d.BigInt())
return nil
Expand All @@ -206,13 +206,13 @@ func (w *Wei) UnmarshalText(b []byte) error {
// unrecognized or missing suffix
d, err := decimal.NewFromString(s)
if err != nil {
return errors.Wrapf(err, "unable to parse %q", s)
return pkgerrors.Wrapf(err, "unable to parse %q", s)
}
if d.IsInteger() {
*w = (Wei)(*d.BigInt())
return nil
}
return errors.Errorf("unable to parse %q", s)
return pkgerrors.Errorf("unable to parse %q", s)
}

func (w *Wei) ToInt() *big.Int {
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/pkg/errors"
pkgerrors "github.com/pkg/errors"
)

const queryTimeout = 10 * time.Second
Expand Down Expand Up @@ -125,7 +125,7 @@ func NewClientWithNodes(lggr logger.Logger, selectionMode string, leaseDuration
// node's remote chain ID matches the local one
func (client *client) Dial(ctx context.Context) error {
if err := client.pool.Dial(ctx); err != nil {
return errors.Wrap(err, "failed to dial pool")
return pkgerrors.Wrap(err, "failed to dial pool")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/pkg/errors"
pkgerrors "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestEthClient_TransactionReceipt(t *testing.T) {

hash := common.HexToHash(txHash)
_, err = ethClient.TransactionReceipt(testutils.Context(t), hash)
require.Equal(t, ethereum.NotFound, errors.Cause(err))
require.Equal(t, ethereum.NotFound, pkgerrors.Cause(err))
}
})
}
Expand Down
Loading
Loading