Skip to content

Commit 94430b7

Browse files
committed
more error messages fixes + removal of pkg/errors
1 parent e1f0879 commit 94430b7

18 files changed

+98
-82
lines changed

lib/utils/seth/seth.go

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package seth
22

33
import (
4+
"errors"
45
"fmt"
56
"regexp"
67
"strings"
78

8-
"github.com/pkg/errors"
99
"github.com/rs/zerolog"
1010

1111
pkg_seth "github.com/smartcontractkit/chainlink-testing-framework/seth"
@@ -112,27 +112,29 @@ func GetChainClient(c config.SethConfig, network blockchain.EVMNetwork) (*pkg_se
112112
func GetChainClientWithConfigFunction(c config.SethConfig, network blockchain.EVMNetwork, configFn ConfigFunction) (*pkg_seth.Client, error) {
113113
readSethCfg := c.GetSethConfig()
114114
if readSethCfg == nil {
115-
return nil, errors.New("Seth config not found")
115+
return nil, fmt.Errorf("Seth config not found in the provided configuration. " +
116+
"Ensure your TOML config file has a [Seth] section with required settings. " +
117+
"See example: https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/seth/seth.toml")
116118
}
117119

118120
sethCfg, err := MergeSethAndEvmNetworkConfigs(network, *readSethCfg)
119121
if err != nil {
120-
return nil, errors.Wrapf(err, "Error merging seth and evm network configs")
122+
return nil, fmt.Errorf("error merging seth and evm network configs: %w", err)
121123
}
122124

123125
err = configFn(&sethCfg)
124126
if err != nil {
125-
return nil, errors.Wrapf(err, "Error applying seth config function")
127+
return nil, fmt.Errorf("error applying seth config function: %w", err)
126128
}
127129

128130
err = ValidateSethNetworkConfig(sethCfg.Network)
129131
if err != nil {
130-
return nil, errors.Wrapf(err, "Error validating seth network config")
132+
return nil, fmt.Errorf("error validating seth network config: %w", err)
131133
}
132134

133135
chainClient, err := pkg_seth.NewClientWithConfig(&sethCfg)
134136
if err != nil {
135-
return nil, errors.Wrapf(err, "Error creating seth client")
137+
return nil, fmt.Errorf("error creating seth client: %w", err)
136138
}
137139

138140
return chainClient, nil
@@ -255,33 +257,47 @@ func MustReplaceSimulatedNetworkUrlWithK8(l zerolog.Logger, network blockchain.E
255257
// ValidateSethNetworkConfig validates the Seth network config
256258
func ValidateSethNetworkConfig(cfg *pkg_seth.Network) error {
257259
if cfg == nil {
258-
return errors.New("network cannot be nil")
260+
return fmt.Errorf("network configuration cannot be nil. " +
261+
"Ensure your Seth config has properly configured network settings")
259262
}
260263
if len(cfg.URLs) == 0 {
261-
return errors.New("URLs are required")
264+
return fmt.Errorf("network URLs are required. " +
265+
"Add RPC endpoint URLs in the 'urls_secret' field of your network config")
262266
}
263267
if len(cfg.PrivateKeys) == 0 {
264-
return errors.New("PrivateKeys are required")
268+
return fmt.Errorf("private keys are required. " +
269+
"Add at least one private key in 'private_keys_secret' or via environment variables")
265270
}
266271
if cfg.TransferGasFee == 0 {
267-
return errors.New("TransferGasFee needs to be above 0. It's the gas fee for a simple transfer transaction")
272+
return fmt.Errorf("transfer_gas_fee must be greater than 0. " +
273+
"This is the gas fee for a simple transfer transaction. " +
274+
"Set 'transfer_gas_fee' in your network config")
268275
}
269276
if cfg.TxnTimeout.Duration() == 0 {
270-
return errors.New("TxnTimeout needs to be above 0. It's the timeout for a transaction")
277+
return fmt.Errorf("transaction timeout must be greater than 0. " +
278+
"Set 'txn_timeout' in your network config (e.g., '30s', '1m')")
271279
}
272280
if cfg.EIP1559DynamicFees {
273281
if cfg.GasFeeCap == 0 {
274-
return errors.New("GasFeeCap needs to be above 0. It's the maximum fee per gas for a transaction (including tip)")
282+
return fmt.Errorf("gas_fee_cap must be greater than 0 for EIP-1559 transactions. " +
283+
"This is the maximum fee per gas (base fee + tip). " +
284+
"Set 'gas_fee_cap' in your network config")
275285
}
276286
if cfg.GasTipCap == 0 {
277-
return errors.New("GasTipCap needs to be above 0. It's the maximum tip per gas for a transaction")
287+
return fmt.Errorf("gas_tip_cap must be greater than 0 for EIP-1559 transactions. " +
288+
"This is the maximum priority fee per gas. " +
289+
"Set 'gas_tip_cap' in your network config")
278290
}
279291
if cfg.GasFeeCap <= cfg.GasTipCap {
280-
return errors.New("GasFeeCap needs to be above GasTipCap (as it is base fee + tip cap)")
292+
return fmt.Errorf("gas_fee_cap (%d) must be greater than gas_tip_cap (%d). "+
293+
"Fee cap should be base fee + tip cap. "+
294+
"Adjust your network config accordingly",
295+
cfg.GasFeeCap, cfg.GasTipCap)
281296
}
282297
} else {
283298
if cfg.GasPrice == 0 {
284-
return errors.New("GasPrice needs to be above 0. It's the price of gas for a transaction")
299+
return fmt.Errorf("gas_price must be greater than 0 for legacy transactions. " +
300+
"Set 'gas_price' in your network config")
285301
}
286302
}
287303

seth/abi_finder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package seth
22

33
import (
4+
"errors"
45
"fmt"
56
"strings"
67

78
"github.com/ethereum/go-ethereum/accounts/abi"
89
"github.com/ethereum/go-ethereum/common"
9-
"github.com/pkg/errors"
1010
)
1111

1212
type ABIFinder struct {

seth/client.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package seth
33
import (
44
"context"
55
"crypto/ecdsa"
6+
"errors"
67
"fmt"
78
"math/big"
89
"net/http"
@@ -21,7 +22,6 @@ import (
2122
"github.com/ethereum/go-ethereum/accounts/abi/bind"
2223
"github.com/ethereum/go-ethereum/common"
2324
"github.com/ethereum/go-ethereum/core/types"
24-
"github.com/pkg/errors"
2525
"github.com/rs/zerolog"
2626
"golang.org/x/sync/errgroup"
2727
)
@@ -89,8 +89,8 @@ func NewClientWithConfig(cfg *Config) (*Client, error) {
8989
initDefaultLogging()
9090

9191
if cfg == nil {
92-
return nil, fmt.Errorf("Seth configuration is nil. "+
93-
"Ensure you're calling NewClientWithConfig() with a valid config, or use NewClient() to load from SETH_CONFIG_PATH environment variable. "+
92+
return nil, fmt.Errorf("Seth configuration is nil. " +
93+
"Ensure you're calling NewClientWithConfig() with a valid config, or use NewClient() to load from SETH_CONFIG_PATH environment variable. " +
9494
"See documentation for configuration examples")
9595
}
9696
if cfgErr := cfg.Validate(); cfgErr != nil {
@@ -199,18 +199,18 @@ func NewClientRaw(
199199
opts ...ClientOpt,
200200
) (*Client, error) {
201201
if cfg == nil {
202-
return nil, fmt.Errorf("Seth configuration is nil. "+
203-
"Provide a valid Config when calling NewClientRaw(). "+
202+
return nil, fmt.Errorf("Seth configuration is nil. " +
203+
"Provide a valid Config when calling NewClientRaw(). " +
204204
"Consider using NewClient() or NewClientWithConfig() instead")
205205
}
206206
if cfgErr := cfg.Validate(); cfgErr != nil {
207207
return nil, cfgErr
208208
}
209209
if cfg.ReadOnly && (len(addrs) > 0 || len(pkeys) > 0) {
210-
return nil, fmt.Errorf("configuration conflict: read-only mode is enabled, but private keys were provided. "+
211-
"Read-only mode is for querying blockchain state only (no transactions).\n"+
212-
"To fix:\n"+
213-
" 1. Remove private keys if you only need to read data\n"+
210+
return nil, fmt.Errorf("configuration conflict: read-only mode is enabled, but private keys were provided. " +
211+
"Read-only mode is for querying blockchain state only (no transactions).\n" +
212+
"To fix:\n" +
213+
" 1. Remove private keys if you only need to read data\n" +
214214
" 2. Set 'read_only = false' in config if you need to send transactions")
215215
}
216216

@@ -219,7 +219,7 @@ func NewClientRaw(
219219
if cfg.ethclient == nil {
220220
L.Info().Msg("Creating new ethereum client")
221221
if len(cfg.Network.URLs) == 0 {
222-
return nil, fmt.Errorf("no RPC URLs provided. "+
222+
return nil, fmt.Errorf("no RPC URLs provided. " +
223223
"Set RPC URLs in your seth.toml config under 'urls_secret = [\"http://...\"]' or provide via WithRpcUrl() when using ClientBuilder")
224224
}
225225

@@ -323,9 +323,9 @@ func NewClientRaw(
323323

324324
if cfg.CheckRpcHealthOnStart {
325325
if cfg.ReadOnly {
326-
return nil, fmt.Errorf("RPC health check is not supported in read-only mode because it requires sending transactions. "+
327-
"Either:\n"+
328-
" 1. Set 'read_only = false' to enable transaction capabilities\n"+
326+
return nil, fmt.Errorf("RPC health check is not supported in read-only mode because it requires sending transactions. " +
327+
"Either:\n" +
328+
" 1. Set 'read_only = false' to enable transaction capabilities\n" +
329329
" 2. Set 'check_rpc_health_on_start = false' to skip the health check")
330330
}
331331
if c.NonceManager == nil {
@@ -338,9 +338,9 @@ func NewClientRaw(
338338
}
339339

340340
if cfg.PendingNonceProtectionEnabled && cfg.ReadOnly {
341-
return nil, fmt.Errorf("pending nonce protection is not supported in read-only mode because it requires transaction monitoring. "+
342-
"Either:\n"+
343-
" 1. Set 'read_only = false' to enable transaction capabilities\n"+
341+
return nil, fmt.Errorf("pending nonce protection is not supported in read-only mode because it requires transaction monitoring. " +
342+
"Either:\n" +
343+
" 1. Set 'read_only = false' to enable transaction capabilities\n" +
344344
" 2. Set 'pending_nonce_protection_enabled = false'")
345345
}
346346

@@ -356,14 +356,14 @@ func NewClientRaw(
356356

357357
if cfg.ephemeral {
358358
if len(c.Addresses) == 0 {
359-
return nil, fmt.Errorf("ephemeral mode requires exactly one root private key to fund ephemeral addresses, but no keys were loaded. "+
360-
"Load the root private key via:\n"+
361-
" 1. SETH_ROOT_PRIVATE_KEY environment variable\n"+
362-
" 2. 'root_private_key' in seth.toml\n"+
359+
return nil, fmt.Errorf("ephemeral mode requires exactly one root private key to fund ephemeral addresses, but no keys were loaded. " +
360+
"Load the root private key via:\n" +
361+
" 1. SETH_ROOT_PRIVATE_KEY environment variable\n" +
362+
" 2. 'root_private_key' in seth.toml\n" +
363363
" 3. WithPrivateKeys() when using ClientBuilder")
364364
}
365365
if cfg.ReadOnly {
366-
return nil, fmt.Errorf("ephemeral mode is not supported in read-only mode because it requires funding transactions. "+
366+
return nil, fmt.Errorf("ephemeral mode is not supported in read-only mode because it requires funding transactions. " +
367367
"Set 'read_only = false' or disable ephemeral mode by removing 'ephemeral_addresses_number' from config")
368368
}
369369
ctx, cancel := context.WithTimeout(context.Background(), c.Cfg.Network.TxnTimeout.D)
@@ -439,9 +439,9 @@ func NewClientRaw(
439439
}
440440

441441
if c.Cfg.GasBump != nil && c.Cfg.GasBump.Retries != 0 && c.Cfg.ReadOnly {
442-
return nil, fmt.Errorf("gas bumping is not supported in read-only mode because it requires sending replacement transactions. "+
443-
"Either:\n"+
444-
" 1. Set 'read_only = false' to enable transaction capabilities\n"+
442+
return nil, fmt.Errorf("gas bumping is not supported in read-only mode because it requires sending replacement transactions. " +
443+
"Either:\n" +
444+
" 1. Set 'read_only = false' to enable transaction capabilities\n" +
445445
" 2. Set 'gas_bump.retries = 0' to disable gas bumping")
446446
}
447447

@@ -1294,10 +1294,10 @@ type DeploymentData struct {
12941294
// name of ABI file (you can omit the .abi suffix).
12951295
func (m *Client) DeployContractFromContractStore(auth *bind.TransactOpts, name string, params ...interface{}) (DeploymentData, error) {
12961296
if m.ContractStore == nil {
1297-
return DeploymentData{}, fmt.Errorf("contract store is nil. Cannot deploy contract from store.\n"+
1298-
"This usually means:\n"+
1299-
" 1. Seth client wasn't properly initialized\n"+
1300-
" 2. ABI directory path is incorrect in config\n"+
1297+
return DeploymentData{}, fmt.Errorf("contract store is nil. Cannot deploy contract from store.\n" +
1298+
"This usually means:\n" +
1299+
" 1. Seth client wasn't properly initialized\n" +
1300+
" 2. ABI directory path is incorrect in config\n" +
13011301
"Ensure 'abi_dir' and 'bin_dir' are set in seth.toml or use DeployContract() with explicit ABI/bytecode")
13021302
}
13031303

seth/client_api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package seth_test
22

33
import (
44
"context"
5+
"errors"
56
"math/big"
67
"sync"
78
"testing"
89
"time"
910

1011
"github.com/ethereum/go-ethereum/core/types"
11-
"github.com/pkg/errors"
1212
"github.com/stretchr/testify/require"
1313

1414
"github.com/smartcontractkit/chainlink-testing-framework/seth"

seth/client_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package seth
22

33
import (
4+
"errors"
45
"fmt"
56
"time"
67

78
"github.com/ethereum/go-ethereum/ethclient/simulated"
8-
"github.com/pkg/errors"
99
)
1010

1111
const (

seth/client_builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package seth_test
22

33
import (
44
"crypto/ecdsa"
5+
"errors"
56
"math/big"
67
"os"
78
"strings"
@@ -13,7 +14,6 @@ import (
1314
"github.com/ethereum/go-ethereum/core/types"
1415
"github.com/ethereum/go-ethereum/crypto"
1516
"github.com/ethereum/go-ethereum/ethclient"
16-
"github.com/pkg/errors"
1717

1818
"github.com/pelletier/go-toml/v2"
1919

seth/client_main_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package seth_test
22

33
import (
44
"context"
5+
"errors"
6+
"fmt"
57
"math/big"
68
"os"
79
"testing"
@@ -11,7 +13,6 @@ import (
1113
"github.com/ethereum/go-ethereum/common"
1214
"github.com/ethereum/go-ethereum/core/types"
1315
"github.com/ethereum/go-ethereum/ethclient/simulated"
14-
"github.com/pkg/errors"
1516
"github.com/stretchr/testify/require"
1617

1718
"github.com/smartcontractkit/chainlink-testing-framework/seth"
@@ -150,7 +151,7 @@ func NewDebugContractSetup() (
150151

151152
nm, err := seth.NewNonceManager(cfg, addrs, pkeys)
152153
if err != nil {
153-
return nil, nil, common.Address{}, common.Address{}, nil, errors.Wrap(err, seth.ErrCreateNonceManager)
154+
return nil, nil, common.Address{}, common.Address{}, nil, fmt.Errorf("failed to create nonce manager: %w", err)
154155
}
155156

156157
c, err := seth.NewClientRaw(cfg, addrs, pkeys, seth.WithContractStore(cs), seth.WithTracer(tracer), seth.WithNonceManager(nm))

seth/cmd/seth.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package seth
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"math/big"
78
"os"
@@ -12,7 +13,6 @@ import (
1213
"github.com/ethereum/go-ethereum/common"
1314
"github.com/ethereum/go-ethereum/ethclient"
1415
"github.com/pelletier/go-toml/v2"
15-
"github.com/pkg/errors"
1616
"github.com/urfave/cli/v2"
1717

1818
"github.com/smartcontractkit/chainlink-testing-framework/seth"
@@ -205,11 +205,11 @@ func RunCLI(args []string) error {
205205
var cfg *seth.Config
206206
d, err := os.ReadFile(cfgPath)
207207
if err != nil {
208-
return errors.Wrap(err, seth.ErrReadSethConfig)
208+
return fmt.Errorf("%s: %w", seth.ErrReadSethConfig, err)
209209
}
210210
err = toml.Unmarshal(d, &cfg)
211211
if err != nil {
212-
return errors.Wrap(err, seth.ErrUnmarshalSethConfig)
212+
return fmt.Errorf("%s: %w", seth.ErrUnmarshalSethConfig, err)
213213
}
214214
absPath, err := filepath.Abs(cfgPath)
215215
if err != nil {
@@ -272,7 +272,7 @@ func RunCLI(args []string) error {
272272
if cfg.Network.Name == seth.DefaultNetworkName {
273273
chainId, err := client.ChainID(context.Background())
274274
if err != nil {
275-
return errors.Wrap(err, "failed to get chain ID")
275+
return fmt.Errorf("failed to get chain ID: %w", err)
276276
}
277277
cfg.Network.ChainID = chainId.Uint64()
278278
}
@@ -298,7 +298,7 @@ func RunCLI(args []string) error {
298298
tx, _, err := client.Client.TransactionByHash(ctx, common.HexToHash(txHash))
299299
cancel()
300300
if err != nil {
301-
return errors.Wrapf(err, "failed to get transaction %s", txHash)
301+
return fmt.Errorf("failed to get transaction %s: %w", txHash, err)
302302
}
303303

304304
_, err = client.Decode(tx, nil)

0 commit comments

Comments
 (0)