Skip to content

Commit

Permalink
Inner errors (#2774)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaLanfranchi authored Oct 4, 2021
1 parent 044aa67 commit c913f35
Show file tree
Hide file tree
Showing 75 changed files with 193 additions and 191 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (argument *Argument) UnmarshalJSON(data []byte) error {
var arg ArgumentMarshaling
err := json.Unmarshal(data, &arg)
if err != nil {
return fmt.Errorf("argument json err: %v", err)
return fmt.Errorf("argument json err: %w", err)
}

argument.Type, err = NewType(arg.Type, arg.InternalType, arg.Components)
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx types.Transac
signer := types.MakeSigner(b.m.ChainConfig, b.pendingBlock.NumberU64())
sender, senderErr := tx.Sender(*signer)
if senderErr != nil {
return fmt.Errorf("invalid transaction: %v", senderErr)
return fmt.Errorf("invalid transaction: %w", senderErr)
}
nonce := b.pendingState.GetNonce(sender)
if tx.GetNonce() != nonce {
Expand Down
4 changes: 2 additions & 2 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
if opts.Nonce == nil {
nonce, err = c.transactor.PendingNonceAt(ensureContext(opts.Context), opts.From)
if err != nil {
return nil, fmt.Errorf("failed to retrieve account nonce: %v", err)
return nil, fmt.Errorf("failed to retrieve account nonce: %w", err)
}
} else {
nonce = opts.Nonce.Uint64()
Expand Down Expand Up @@ -252,7 +252,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
msg := ethereum.CallMsg{From: opts.From, To: contract, GasPrice: gasPrice, Value: value, Data: input}
gasLimit, err = c.transactor.EstimateGas(ensureContext(opts.Context), msg)
if err != nil {
return nil, fmt.Errorf("failed to estimate gas needed: %v", err)
return nil, fmt.Errorf("failed to estimate gas needed: %w", err)
}
}
// Create the transaction, sign it and schedule it for execution
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
if lang == LangGo {
code, err := format.Source(buffer.Bytes())
if err != nil {
return "", fmt.Errorf("%v\n%s", err, buffer)
return "", fmt.Errorf("%w\n%s", err, buffer)
}
return string(code), nil
}
Expand Down
4 changes: 2 additions & 2 deletions accounts/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
typ.Elem = &embeddedType
typ.Size, err = strconv.Atoi(intz[0])
if err != nil {
return Type{}, fmt.Errorf("abi: error parsing variable size: %v", err)
return Type{}, fmt.Errorf("abi: error parsing variable size: %w", err)
}
typ.stringKind = embeddedType.stringKind + sliced
} else {
Expand All @@ -124,7 +124,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
var err error
varSize, err = strconv.Atoi(parsedType[2])
if err != nil {
return Type{}, fmt.Errorf("abi: error parsing variable size: %v", err)
return Type{}, fmt.Errorf("abi: error parsing variable size: %w", err)
}
} else {
if parsedType[0] == "uint" || parsedType[0] == "int" {
Expand Down
4 changes: 2 additions & 2 deletions accounts/abi/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ type unpackTest struct {
func (test unpackTest) checkError(err error) error {
if err != nil {
if len(test.err) == 0 {
return fmt.Errorf("expected no err but got: %v", err)
return fmt.Errorf("expected no err but got: %w", err)
} else if err.Error() != test.err {
return fmt.Errorf("expected err: '%v' got err: %q", test.err, err)
return fmt.Errorf("expected err: '%v' got err: %w", test.err, err)
}
} else if len(test.err) > 0 {
return fmt.Errorf("expected err: %v but got none", test.err)
Expand Down
14 changes: 7 additions & 7 deletions cmd/hack/db/lmdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,13 +945,13 @@ func TextInfo(chaindata string, visStream io.Writer) error {

f, err := os.Open(datafile)
if err != nil {
return fmt.Errorf("opening %v: %v", MdbxDataFile, err)
return fmt.Errorf("opening %v: %w", MdbxDataFile, err)
}
defer f.Close()
var meta [PageSize]byte
// Read meta page 0
if _, err = f.ReadAt(meta[:], 0*PageSize); err != nil {
return fmt.Errorf("reading meta page 0: %v", err)
return fmt.Errorf("reading meta page 0: %w", err)
}

header1 := new(header)
Expand All @@ -967,12 +967,12 @@ func TextInfo(chaindata string, visStream io.Writer) error {
// meta1.print()

if err != nil {
return fmt.Errorf("reading meta page 0: %v", err)
return fmt.Errorf("reading meta page 0: %w", err)
}

// Read meta page 1
if _, err = f.ReadAt(meta[:], 1*PageSize); err != nil {
return fmt.Errorf("reading meta page 1: %v", err)
return fmt.Errorf("reading meta page 1: %w", err)
}

header2 := new(header)
Expand All @@ -988,7 +988,7 @@ func TextInfo(chaindata string, visStream io.Writer) error {
// meta2.print()

if err != nil {
return fmt.Errorf("reading meta page 1: %v", err)
return fmt.Errorf("reading meta page 1: %w", err)
}

var freeRoot, mainRoot uint32
Expand Down Expand Up @@ -1115,7 +1115,7 @@ func _conditions(f io.ReaderAt, visStream io.Writer, node *mdbx_node, _header *h
func readPages(f io.ReaderAt, visStream io.Writer, pgno uint32, blockID *int, parentBlock int, level *int) error {
var page [PageSize]byte
if _, err := f.ReadAt(page[:], int64(pgno*PageSize)); err != nil {
return fmt.Errorf("reading page: %v, error: %v", pgno, err)
return fmt.Errorf("reading page: %v, error: %w", pgno, err)
}

_header := new(header)
Expand Down Expand Up @@ -1193,7 +1193,7 @@ func readPages(f io.ReaderAt, visStream io.Writer, pgno uint32, blockID *int, pa
func freeDBPages(f io.ReaderAt, visStream io.Writer, freeRoot uint32) error {
var page [PageSize]byte
if _, err := f.ReadAt(page[:], int64(freeRoot*PageSize)); err != nil {
return fmt.Errorf("reading page: %v, error: %v", freeRoot, err)
return fmt.Errorf("reading page: %v, error: %w", freeRoot, err)
}

_header := new(header)
Expand Down
26 changes: 13 additions & 13 deletions cmd/hack/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ func mphf(chaindata string, block uint64) error {
statefile := "statedump.dat"
if _, err := os.Stat(statefile); err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("not sure if statedump.dat exists: %v", err)
return fmt.Errorf("not sure if statedump.dat exists: %w", err)
}
if err = dumpState(chaindata, statefile); err != nil {
return err
Expand Down Expand Up @@ -1589,7 +1589,7 @@ func compress(chaindata string, block uint64) error {
statefile := "statedump.dat"
if _, err := os.Stat(statefile); err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("not sure if statedump.dat exists: %v", err)
return fmt.Errorf("not sure if statedump.dat exists: %w", err)
}
if err = dumpState(chaindata, statefile); err != nil {
return err
Expand Down Expand Up @@ -2490,7 +2490,7 @@ func extractHeaders(chaindata string, block uint64) error {
blockHash := common.BytesToHash(k[8:])
var header types.Header
if err = rlp.DecodeBytes(v, &header); err != nil {
return fmt.Errorf("decoding header from %x: %v", v, err)
return fmt.Errorf("decoding header from %x: %w", v, err)
}
fmt.Printf("Header %d %x: stateRoot %x, parentHash %x, diff %d\n", blockNumber, blockHash, header.Root, header.ParentHash, header.Difficulty)
}
Expand Down Expand Up @@ -2664,7 +2664,7 @@ func fixTd(chaindata string) error {
fmt.Printf("Missing TD record for %x, fixing\n", k)
var header types.Header
if err = rlp.DecodeBytes(v, &header); err != nil {
return fmt.Errorf("decoding header from %x: %v", v, err)
return fmt.Errorf("decoding header from %x: %w", v, err)
}
if header.Number.Uint64() == 0 {
continue
Expand All @@ -2674,17 +2674,17 @@ func fixTd(chaindata string) error {
copy(parentK[8:], header.ParentHash[:])
var parentTdRec []byte
if parentTdRec, err = tx.GetOne(kv.HeaderTD, parentK[:]); err != nil {
return fmt.Errorf("reading parentTd Rec for %d: %v", header.Number.Uint64(), err)
return fmt.Errorf("reading parentTd Rec for %d: %w", header.Number.Uint64(), err)
}
var parentTd big.Int
if err = rlp.DecodeBytes(parentTdRec, &parentTd); err != nil {
return fmt.Errorf("decoding parent Td record for block %d, from %x: %v", header.Number.Uint64(), parentTdRec, err)
return fmt.Errorf("decoding parent Td record for block %d, from %x: %w", header.Number.Uint64(), parentTdRec, err)
}
var td big.Int
td.Add(&parentTd, header.Difficulty)
var newHv []byte
if newHv, err = rlp.EncodeToBytes(&td); err != nil {
return fmt.Errorf("encoding td record for block %d: %v", header.Number.Uint64(), err)
return fmt.Errorf("encoding td record for block %d: %w", header.Number.Uint64(), err)
}
if err = tx.Put(kv.HeaderTD, k, newHv); err != nil {
return err
Expand Down Expand Up @@ -2781,7 +2781,7 @@ func fixState(chaindata string) error {
}
var header types.Header
if err = rlp.DecodeBytes(hv, &header); err != nil {
return fmt.Errorf("decoding header from %x: %v", v, err)
return fmt.Errorf("decoding header from %x: %w", v, err)
}
if header.Number.Uint64() > 1 {
var parentK [40]byte
Expand Down Expand Up @@ -3142,10 +3142,10 @@ func scanReceipts(chaindata string, block uint64) error {
buf.Reset()
err := cbor.Marshal(&buf, receipts1)
if err != nil {
return fmt.Errorf("encode block receipts for block %d: %v", blockNum, err)
return fmt.Errorf("encode block receipts for block %d: %w", blockNum, err)
}
if err = tx.Put(kv.Receipts, key[:], buf.Bytes()); err != nil {
return fmt.Errorf("writing receipts for block %d: %v", blockNum, err)
return fmt.Errorf("writing receipts for block %d: %w", blockNum, err)
}
if _, err = w.Write([]byte(fmt.Sprintf("%d\n", blockNum))); err != nil {
return err
Expand All @@ -3172,7 +3172,7 @@ func runBlock(ibs *state.IntraBlockState, txnWriter state.StateWriter, blockWrit
ibs.Prepare(tx.Hash(), block.Hash(), i)
receipt, _, err := core.ApplyTransaction(chainConfig, getHeader, engine, nil, gp, ibs, txnWriter, header, tx, usedGas, vmConfig, contractHasTEVM)
if err != nil {
return nil, fmt.Errorf("could not apply tx %d [%x] failed: %v", i, tx.Hash(), err)
return nil, fmt.Errorf("could not apply tx %d [%x] failed: %w", i, tx.Hash(), err)
}
receipts = append(receipts, receipt)
//fmt.Printf("%d, cumulative gas: %d\n", i, receipt.CumulativeGasUsed)
Expand All @@ -3181,11 +3181,11 @@ func runBlock(ibs *state.IntraBlockState, txnWriter state.StateWriter, blockWrit
if !vmConfig.ReadOnly {
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
if _, err := engine.FinalizeAndAssemble(chainConfig, header, ibs, block.Transactions(), block.Uncles(), receipts, nil, nil, nil, nil); err != nil {
return nil, fmt.Errorf("finalize of block %d failed: %v", block.NumberU64(), err)
return nil, fmt.Errorf("finalize of block %d failed: %w", block.NumberU64(), err)
}

if err := ibs.CommitBlock(rules, blockWriter); err != nil {
return nil, fmt.Errorf("committing block %d failed: %v", block.NumberU64(), err)
return nil, fmt.Errorf("committing block %d failed: %w", block.NumberU64(), err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/rpcdaemon/commands/erigon_receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (api *ErigonImpl) GetLogsByHash(ctx context.Context, hash common.Hash) ([][
}
receipts, err := getReceipts(ctx, tx, chainConfig, block, block.Body().SendersFromTxs())
if err != nil {
return nil, fmt.Errorf("getReceipts error: %v", err)
return nil, fmt.Errorf("getReceipts error: %w", err)
}

logs := make([][]*types.Log, len(receipts))
Expand All @@ -55,7 +55,7 @@ func (api *ErigonImpl) GetLogsByHash(ctx context.Context, hash common.Hash) ([][

// receipts, err := getReceipts(ctx, tx, *number, hash)
// if err != nil {
// return nil, fmt.Errorf("getReceipts error: %v", err)
// return nil, fmt.Errorf("getReceipts error: %w", err)
// }

// logs := make([][]*types.Log, len(receipts))
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpcdaemon/commands/eth_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func (api *APIImpl) GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error) {
tx, err1 := api.db.BeginRo(ctx)
if err1 != nil {
return nil, fmt.Errorf("getBalance cannot open tx: %v", err1)
return nil, fmt.Errorf("getBalance cannot open tx: %w", err1)
}
defer tx.Rollback()
blockNumber, _, err := rpchelper.GetBlockNumber(blockNrOrHash, tx, api.filters)
Expand All @@ -41,7 +41,7 @@ func (api *APIImpl) GetBalance(ctx context.Context, address common.Address, bloc
func (api *APIImpl) GetTransactionCount(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Uint64, error) {
tx, err1 := api.db.BeginRo(ctx)
if err1 != nil {
return nil, fmt.Errorf("getTransactionCount cannot open tx: %v", err1)
return nil, fmt.Errorf("getTransactionCount cannot open tx: %w", err1)
}
defer tx.Rollback()
blockNumber, _, err := rpchelper.GetBlockNumber(blockNrOrHash, tx, api.filters)
Expand All @@ -61,7 +61,7 @@ func (api *APIImpl) GetTransactionCount(ctx context.Context, address common.Addr
func (api *APIImpl) GetCode(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) {
tx, err1 := api.db.BeginRo(ctx)
if err1 != nil {
return nil, fmt.Errorf("getCode cannot open tx: %v", err1)
return nil, fmt.Errorf("getCode cannot open tx: %w", err1)
}
defer tx.Rollback()
blockNumber, _, err := rpchelper.GetBlockNumber(blockNrOrHash, tx, api.filters)
Expand Down
4 changes: 2 additions & 2 deletions cmd/rpcdaemon/commands/eth_receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, hash common.Hash)
}
receipts, err := getReceipts(ctx, tx, cc, block, block.Body().SendersFromTxs())
if err != nil {
return nil, fmt.Errorf("getReceipts error: %v", err)
return nil, fmt.Errorf("getReceipts error: %w", err)
}
if len(receipts) <= int(txIndex) {
return nil, fmt.Errorf("block has less receipts than expected: %d <= %d, block: %d", len(receipts), int(txIndex), blockNumber)
Expand Down Expand Up @@ -295,7 +295,7 @@ func (api *APIImpl) GetBlockReceipts(ctx context.Context, number rpc.BlockNumber
}
receipts, err := getReceipts(ctx, tx, chainConfig, block, block.Body().SendersFromTxs())
if err != nil {
return nil, fmt.Errorf("getReceipts error: %v", err)
return nil, fmt.Errorf("getReceipts error: %w", err)
}
result := make([]map[string]interface{}, 0, len(receipts))
for _, receipt := range receipts {
Expand Down
2 changes: 1 addition & 1 deletion cmd/rpcdaemon/commands/rpc_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func getBlockNumber(number rpc.BlockNumber, tx kv.Tx) (uint64, error) {
func getLatestBlockNumber(tx kv.Tx) (uint64, error) {
blockNum, err := stages.GetStageProgress(tx, stages.Execution)
if err != nil {
return 0, fmt.Errorf("getting latest block number: %v", err)
return 0, fmt.Errorf("getting latest block number: %w", err)
}

return blockNum, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/rpcdaemon/commands/storage_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func StorageRangeAt(stateReader *state.PlainState, contractAddress common.Addres
resultCount++
return resultCount <= maxResult
}, maxResult+1); err != nil {
return StorageRangeResult{}, fmt.Errorf("error walking over storage: %v", err)
return StorageRangeResult{}, fmt.Errorf("error walking over storage: %w", err)
}
return result, nil
}
2 changes: 1 addition & 1 deletion cmd/rpcdaemon/commands/trace_filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, str
dbtx, err1 := api.kv.BeginRo(ctx)
if err1 != nil {
stream.WriteNil()
return fmt.Errorf("traceFilter cannot open tx: %v", err1)
return fmt.Errorf("traceFilter cannot open tx: %w", err1)
}
defer dbtx.Rollback()

Expand Down
2 changes: 1 addition & 1 deletion cmd/rpctest/rpctest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func requestAndCompare(request string, methodName string, errCtx string, reqGen
oeRespFile, _ := os.Create("oe-response.json") //nolint:errcheck
oeRespFile.Write(resg.Response) //nolint:errcheck
oeRespFile.Close() //nolint:errcheck
return fmt.Errorf("different results for method %s, errCtx %s: %v\nRequest in file request.json, Erigon response in file erigon-response.json, Geth/OE response in file oe-response.json", methodName, errCtx, err)
return fmt.Errorf("different results for method %s, errCtx %s: %w\nRequest in file request.json, Erigon response in file erigon-response.json, Geth/OE response in file oe-response.json", methodName, errCtx, err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/snapshots/generator/commands/generate_body_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func BodySnapshot(ctx context.Context, logger log.Logger, dbPath, snapshotPath s

hash, err = rawdb.ReadCanonicalHash(tx, i)
if err != nil {
return fmt.Errorf("getting canonical hash for block %d: %v", i, err)
return fmt.Errorf("getting canonical hash for block %d: %w", i, err)
}
body := rawdb.ReadBodyRLP(tx, hash, i)
if err = sntx.Put(kv.BlockBody, dbutils.BlockBodyKey(i, hash), body); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func HeaderSnapshot(ctx context.Context, logger log.Logger, dbPath, snapshotPath

hash, err = rawdb.ReadCanonicalHash(tx, i)
if err != nil {
return fmt.Errorf("getting canonical hash for block %d: %v", i, err)
return fmt.Errorf("getting canonical hash for block %d: %w", i, err)
}
header = rawdb.ReadHeaderRLP(tx, hash, i)
if len(header) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/snapshots/generator/commands/generate_state_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func GenerateStateSnapshot(ctx context.Context, logger log.Logger, dbPath, snaps

var acc accounts.Account
if err = acc.DecodeForStorage(v); err != nil {
return false, fmt.Errorf("decoding %x for %x: %v", v, k, err)
return false, fmt.Errorf("decoding %x for %x: %w", v, k, err)
}

if acc.Incarnation > 0 {
Expand Down Expand Up @@ -125,7 +125,7 @@ func GenerateStateSnapshot(ctx context.Context, logger log.Logger, dbPath, snaps
if acc.IsEmptyCodeHash() {
codeHash, err1 := tx2.GetOne(kv.PlainContractCode, storagePrefix)
if err1 != nil && errors.Is(err1, ethdb.ErrKeyNotFound) {
return false, fmt.Errorf("getting code hash for %x: %v", k, err1)
return false, fmt.Errorf("getting code hash for %x: %w", k, err1)
}
if len(codeHash) > 0 {
code, err1 := tx2.GetOne(kv.Code, codeHash)
Expand Down
2 changes: 1 addition & 1 deletion cmd/snapshots/tracker/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func ParseRequest(r *http.Request) (AnnounceReq, error) {
}
port, err := strconv.Atoi(q.Get("port"))
if err != nil {
return AnnounceReq{}, fmt.Errorf("port: %v - %w", q.Get("port"), err)
return AnnounceReq{}, fmt.Errorf("port: %v - %w", q.Get("port"), err)
}

res := AnnounceReq{
Expand Down
Loading

0 comments on commit c913f35

Please sign in to comment.