Skip to content

Commit

Permalink
replace multierr.Append and multierr.AppendInto with errors.Join
Browse files Browse the repository at this point in the history
  • Loading branch information
poopoothegorilla committed Jan 18, 2024
1 parent 558613d commit e23fc20
Show file tree
Hide file tree
Showing 39 changed files with 447 additions and 463 deletions.
5 changes: 2 additions & 3 deletions core/chains/evm/config/chain_scoped.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package config

import (
"errors"
"math/big"
"time"

"go.uber.org/multierr"

ocr "github.com/smartcontractkit/libocr/offchainreporting"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types"

Expand Down Expand Up @@ -57,7 +56,7 @@ func (c *ChainScoped) Validate() (err error) {
DataSourceGracePeriod: c.EVM().OCR().ObservationGracePeriod(),
}
if ocrerr := ocr.SanityCheckLocalConfig(lc); ocrerr != nil {
err = multierr.Append(err, ocrerr)
err = errors.Join(err, ocrerr)
}
return
}
Expand Down
74 changes: 37 additions & 37 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package toml

import (
"errors"
"fmt"
"net/url"
"slices"
Expand All @@ -9,7 +10,6 @@ import (
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
"github.com/pelletier/go-toml/v2"
"github.com/shopspring/decimal"
"go.uber.org/multierr"
"gopkg.in/guregu/null.v4"

commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"
Expand Down Expand Up @@ -39,7 +39,7 @@ func (cs EVMConfigs) validateKeys() (err error) {
chainIDs := commonconfig.UniqueStrings{}
for i, c := range cs {
if chainIDs.IsDupeFmt(c.ChainID) {
err = multierr.Append(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), c.ChainID.String()))
err = errors.Join(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), c.ChainID.String()))
}
}

Expand All @@ -48,7 +48,7 @@ func (cs EVMConfigs) validateKeys() (err error) {
for i, c := range cs {
for j, n := range c.Nodes {
if names.IsDupe(n.Name) {
err = multierr.Append(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.Name", i, j), *n.Name))
err = errors.Join(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.Name", i, j), *n.Name))
}
}
}
Expand All @@ -59,7 +59,7 @@ func (cs EVMConfigs) validateKeys() (err error) {
for j, n := range c.Nodes {
u := (*url.URL)(n.WSURL)
if wsURLs.IsDupeFmt(u) {
err = multierr.Append(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.WSURL", i, j), u.String()))
err = errors.Join(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.WSURL", i, j), u.String()))
}
}
}
Expand All @@ -70,7 +70,7 @@ func (cs EVMConfigs) validateKeys() (err error) {
for j, n := range c.Nodes {
u := (*url.URL)(n.HTTPURL)
if httpURLs.IsDupeFmt(u) {
err = multierr.Append(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.HTTPURL", i, j), u.String()))
err = errors.Join(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.HTTPURL", i, j), u.String()))
}
}
}
Expand Down Expand Up @@ -289,29 +289,29 @@ func (c *EVMConfig) SetFrom(f *EVMConfig) {

func (c *EVMConfig) ValidateConfig() (err error) {
if c.ChainID == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
err = errors.Join(err, commonconfig.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
} else if c.ChainID.String() == "" {
err = multierr.Append(err, commonconfig.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
err = errors.Join(err, commonconfig.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
} else if must, ok := ChainTypeForID(c.ChainID); ok { // known chain id
if c.ChainType == nil && must != "" {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "ChainType",
err = errors.Join(err, commonconfig.ErrMissing{Name: "ChainType",
Msg: fmt.Sprintf("only %q can be used with this chain id", must)})
} else if c.ChainType != nil && *c.ChainType != string(must) {
if *c.ChainType == "" {
err = multierr.Append(err, commonconfig.ErrEmpty{Name: "ChainType",
err = errors.Join(err, commonconfig.ErrEmpty{Name: "ChainType",
Msg: fmt.Sprintf("only %q can be used with this chain id", must)})
} else if must == "" {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
Msg: "must not be set with this chain id"})
} else {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
Msg: fmt.Sprintf("only %q can be used with this chain id", must)})
}
}
}

if len(c.Nodes) == 0 {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
err = errors.Join(err, commonconfig.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
} else {
var hasPrimary bool
for _, n := range c.Nodes {
Expand All @@ -322,12 +322,12 @@ func (c *EVMConfig) ValidateConfig() (err error) {
break
}
if !hasPrimary {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Nodes",
err = errors.Join(err, commonconfig.ErrMissing{Name: "Nodes",
Msg: "must have at least one primary node with WSURL"})
}
}

err = multierr.Append(err, c.Chain.ValidateConfig())
err = errors.Join(err, c.Chain.ValidateConfig())

return
}
Expand Down Expand Up @@ -376,24 +376,24 @@ func (c *Chain) ValidateConfig() (err error) {
chainType = config.ChainType(*c.ChainType)
}
if !chainType.IsValid() {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
Msg: config.ErrInvalidChainType.Error()})
}

if c.GasEstimator.BumpTxDepth != nil && *c.GasEstimator.BumpTxDepth > *c.Transactions.MaxInFlight {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "GasEstimator.BumpTxDepth", Value: *c.GasEstimator.BumpTxDepth,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "GasEstimator.BumpTxDepth", Value: *c.GasEstimator.BumpTxDepth,
Msg: "must be less than or equal to Transactions.MaxInFlight"})
}
if *c.HeadTracker.HistoryDepth < *c.FinalityDepth {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "HeadTracker.HistoryDepth", Value: *c.HeadTracker.HistoryDepth,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "HeadTracker.HistoryDepth", Value: *c.HeadTracker.HistoryDepth,
Msg: "must be equal to or greater than FinalityDepth"})
}
if *c.FinalityDepth < 1 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "FinalityDepth", Value: *c.FinalityDepth,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "FinalityDepth", Value: *c.FinalityDepth,
Msg: "must be greater than or equal to 1"})
}
if *c.MinIncomingConfirmations < 1 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "MinIncomingConfirmations", Value: *c.MinIncomingConfirmations,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "MinIncomingConfirmations", Value: *c.MinIncomingConfirmations,
Msg: "must be greater than or equal to 1"})
}
return
Expand Down Expand Up @@ -486,36 +486,36 @@ type GasEstimator struct {

func (e *GasEstimator) ValidateConfig() (err error) {
if uint64(*e.BumpPercent) < legacypool.DefaultConfig.PriceBump {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "BumpPercent", Value: *e.BumpPercent,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "BumpPercent", Value: *e.BumpPercent,
Msg: fmt.Sprintf("may not be less than Geth's default of %d", legacypool.DefaultConfig.PriceBump)})
}
if e.TipCapDefault.Cmp(e.TipCapMin) < 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "TipCapDefault", Value: e.TipCapDefault,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "TipCapDefault", Value: e.TipCapDefault,
Msg: "must be greater than or equal to TipCapMinimum"})
}
if e.FeeCapDefault.Cmp(e.TipCapDefault) < 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "FeeCapDefault", Value: e.TipCapDefault,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "FeeCapDefault", Value: e.TipCapDefault,
Msg: "must be greater than or equal to TipCapDefault"})
}
if *e.Mode == "FixedPrice" && *e.BumpThreshold == 0 && *e.EIP1559DynamicFees && e.FeeCapDefault.Cmp(e.PriceMax) != 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "FeeCapDefault", Value: e.FeeCapDefault,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "FeeCapDefault", Value: e.FeeCapDefault,
Msg: fmt.Sprintf("must be equal to PriceMax (%s) since you are using FixedPrice estimation with gas bumping disabled in "+
"EIP1559 mode - PriceMax will be used as the FeeCap for transactions instead of FeeCapDefault", e.PriceMax)})
} else if e.FeeCapDefault.Cmp(e.PriceMax) > 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "FeeCapDefault", Value: e.FeeCapDefault,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "FeeCapDefault", Value: e.FeeCapDefault,
Msg: fmt.Sprintf("must be less than or equal to PriceMax (%s)", e.PriceMax)})
}

if e.PriceMin.Cmp(e.PriceDefault) > 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "PriceMin", Value: e.PriceMin,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "PriceMin", Value: e.PriceMin,
Msg: "must be less than or equal to PriceDefault"})
}
if e.PriceMax.Cmp(e.PriceDefault) < 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "PriceMax", Value: e.PriceMin,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "PriceMax", Value: e.PriceMin,
Msg: "must be greater than or equal to PriceDefault"})
}
if *e.Mode == "BlockHistory" && *e.BlockHistory.BlockHistorySize <= 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "BlockHistory.BlockHistorySize", Value: *e.BlockHistory.BlockHistorySize,
err = errors.Join(err, commonconfig.ErrInvalid{Name: "BlockHistory.BlockHistorySize", Value: *e.BlockHistory.BlockHistorySize,
Msg: "must be greater than or equal to 1 with BlockHistory Mode"})
}

Expand Down Expand Up @@ -642,7 +642,7 @@ func (ks KeySpecificConfig) ValidateConfig() (err error) {
for _, k := range ks {
addr := k.Key.String()
if _, ok := addrs[addr]; ok {
err = multierr.Append(err, commonconfig.NewErrDuplicate("Key", addr))
err = errors.Join(err, commonconfig.NewErrDuplicate("Key", addr))
} else {
addrs[addr] = struct{}{}
}
Expand Down Expand Up @@ -749,9 +749,9 @@ type Node struct {

func (n *Node) ValidateConfig() (err error) {
if n.Name == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Name", Msg: "required for all nodes"})
err = errors.Join(err, commonconfig.ErrMissing{Name: "Name", Msg: "required for all nodes"})
} else if *n.Name == "" {
err = multierr.Append(err, commonconfig.ErrEmpty{Name: "Name", Msg: "required for all nodes"})
err = errors.Join(err, commonconfig.ErrEmpty{Name: "Name", Msg: "required for all nodes"})
}

var sendOnly bool
Expand All @@ -760,34 +760,34 @@ func (n *Node) ValidateConfig() (err error) {
}
if n.WSURL == nil {
if !sendOnly {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "WSURL", Msg: "required for primary nodes"})
err = errors.Join(err, commonconfig.ErrMissing{Name: "WSURL", Msg: "required for primary nodes"})
}
} else if n.WSURL.IsZero() {
if !sendOnly {
err = multierr.Append(err, commonconfig.ErrEmpty{Name: "WSURL", Msg: "required for primary nodes"})
err = errors.Join(err, commonconfig.ErrEmpty{Name: "WSURL", Msg: "required for primary nodes"})
}
} else {
switch n.WSURL.Scheme {
case "ws", "wss":
default:
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "WSURL", Value: n.WSURL.Scheme, Msg: "must be ws or wss"})
err = errors.Join(err, commonconfig.ErrInvalid{Name: "WSURL", Value: n.WSURL.Scheme, Msg: "must be ws or wss"})
}
}

if n.HTTPURL == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "HTTPURL", Msg: "required for all nodes"})
err = errors.Join(err, commonconfig.ErrMissing{Name: "HTTPURL", Msg: "required for all nodes"})
} else if n.HTTPURL.IsZero() {
err = multierr.Append(err, commonconfig.ErrEmpty{Name: "HTTPURL", Msg: "required for all nodes"})
err = errors.Join(err, commonconfig.ErrEmpty{Name: "HTTPURL", Msg: "required for all nodes"})
} else {
switch n.HTTPURL.Scheme {
case "http", "https":
default:
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "HTTPURL", Value: n.HTTPURL.Scheme, Msg: "must be http or https"})
err = errors.Join(err, commonconfig.ErrInvalid{Name: "HTTPURL", Value: n.HTTPURL.Scheme, Msg: "must be http or https"})
}
}

if n.Order != nil && (*n.Order < 1 || *n.Order > 100) {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "Order", Value: *n.Order, Msg: "must be between 1 and 100"})
err = errors.Join(err, commonconfig.ErrInvalid{Name: "Order", Value: *n.Order, Msg: "must be between 1 and 100"})
} else if n.Order == nil {
z := int32(100)
n.Order = &z
Expand Down
13 changes: 6 additions & 7 deletions core/cmd/admin_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/manyminds/api2go/jsonapi"
"github.com/urfave/cli"
"go.uber.org/multierr"

cutils "github.com/smartcontractkit/chainlink-common/pkg/utils"

Expand Down Expand Up @@ -186,7 +185,7 @@ func (s *Shell) ListUsers(_ *cli.Context) (err error) {
}
defer func() {
if cerr := resp.Body.Close(); cerr != nil {
err = multierr.Append(err, cerr)
err = errors.Join(err, cerr)
}
}()

Expand All @@ -201,7 +200,7 @@ func (s *Shell) CreateUser(c *cli.Context) (err error) {
}
defer func() {
if cerr := resp.Body.Close(); cerr != nil {
err = multierr.Append(err, cerr)
err = errors.Join(err, cerr)
}
}()
var links jsonapi.Links
Expand Down Expand Up @@ -240,7 +239,7 @@ func (s *Shell) CreateUser(c *cli.Context) (err error) {
}
defer func() {
if cerr := response.Body.Close(); cerr != nil {
err = multierr.Append(err, cerr)
err = errors.Join(err, cerr)
}
}()

Expand Down Expand Up @@ -269,7 +268,7 @@ func (s *Shell) ChangeRole(c *cli.Context) (err error) {
}
defer func() {
if cerr := response.Body.Close(); cerr != nil {
err = multierr.Append(err, cerr)
err = errors.Join(err, cerr)
}
}()

Expand All @@ -289,7 +288,7 @@ func (s *Shell) DeleteUser(c *cli.Context) (err error) {
}
defer func() {
if cerr := response.Body.Close(); cerr != nil {
err = multierr.Append(err, cerr)
err = errors.Join(err, cerr)
}
}()

Expand All @@ -304,7 +303,7 @@ func (s *Shell) Status(c *cli.Context) error {
}
defer func() {
if cerr := resp.Body.Close(); cerr != nil {
err = multierr.Append(err, cerr)
err = errors.Join(err, cerr)
}
}()

Expand Down
8 changes: 4 additions & 4 deletions core/cmd/blocks_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package cmd

import (
"bytes"
"errors"
"fmt"
"net/url"
"strconv"

"github.com/pkg/errors"
pkgerrors "github.com/pkg/errors"
"github.com/urfave/cli"
"go.uber.org/multierr"
)

func initBlocksSubCmds(s *Shell) []cli.Command {
Expand Down Expand Up @@ -41,7 +41,7 @@ func initBlocksSubCmds(s *Shell) []cli.Command {
func (s *Shell) ReplayFromBlock(c *cli.Context) (err error) {
blockNumber := c.Int64("block-number")
if blockNumber <= 0 {
return s.errorOut(errors.New("Must pass a positive value in '--block-number' parameter"))
return s.errorOut(pkgerrors.New("Must pass a positive value in '--block-number' parameter"))
}

v := url.Values{}
Expand All @@ -64,7 +64,7 @@ func (s *Shell) ReplayFromBlock(c *cli.Context) (err error) {

defer func() {
if cerr := resp.Body.Close(); cerr != nil {
err = multierr.Append(err, cerr)
err = errors.Join(err, cerr)
}
}()

Expand Down
7 changes: 3 additions & 4 deletions core/cmd/bridge_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strconv"

"github.com/urfave/cli"
"go.uber.org/multierr"

"github.com/smartcontractkit/chainlink/v2/core/web/presenters"
)
Expand Down Expand Up @@ -97,7 +96,7 @@ func (s *Shell) ShowBridge(c *cli.Context) (err error) {
}
defer func() {
if cerr := resp.Body.Close(); cerr != nil {
err = multierr.Append(err, cerr)
err = errors.Join(err, cerr)
}
}()

Expand All @@ -121,7 +120,7 @@ func (s *Shell) CreateBridge(c *cli.Context) (err error) {
}
defer func() {
if cerr := resp.Body.Close(); cerr != nil {
err = multierr.Append(err, cerr)
err = errors.Join(err, cerr)
}
}()

Expand All @@ -140,7 +139,7 @@ func (s *Shell) RemoveBridge(c *cli.Context) (err error) {
}
defer func() {
if cerr := resp.Body.Close(); cerr != nil {
err = multierr.Append(err, cerr)
err = errors.Join(err, cerr)
}
}()

Expand Down
Loading

0 comments on commit e23fc20

Please sign in to comment.