Skip to content

Commit 59d398b

Browse files
committed
trie: print error log instead of panic directly
1 parent 225e20b commit 59d398b

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

trie/stacktrie.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import (
2121
"bytes"
2222
"encoding/gob"
2323
"errors"
24-
"fmt"
2524
"io"
2625
"sync"
2726

2827
"github.com/ethereum/go-ethereum/common"
2928
"github.com/ethereum/go-ethereum/core/types"
29+
"github.com/ethereum/go-ethereum/log"
3030
)
3131

3232
var ErrCommitDisabled = errors.New("no database for committing")
@@ -212,10 +212,11 @@ func (st *StackTrie) Update(key, value []byte) error {
212212
return nil
213213
}
214214

215-
// MustUpdate is a wrapper of Update and panic if any error is encountered.
215+
// MustUpdate is a wrapper of Update and will omit any encountered error but
216+
// just print out an error message.
216217
func (st *StackTrie) MustUpdate(key, value []byte) {
217218
if err := st.Update(key, value); err != nil {
218-
panic(fmt.Errorf("unexpected error in StackTrie.Update: %w", err))
219+
log.Error("Unhandled trie error in StackTrie.Update", "err", err)
219220
}
220221
}
221222

trie/trie.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/ethereum/go-ethereum/common"
2626
"github.com/ethereum/go-ethereum/core/types"
27+
"github.com/ethereum/go-ethereum/log"
2728
)
2829

2930
// Trie is a Merkle Patricia Trie. Use New to create a trie that sits on
@@ -104,11 +105,12 @@ func (t *Trie) NodeIterator(start []byte) NodeIterator {
104105
return newNodeIterator(t, start)
105106
}
106107

107-
// MustGet is a wrapper of Get and panic if any error is encountered.
108+
// MustGet is a wrapper of Get and will omit any encountered error but just
109+
// print out an error message.
108110
func (t *Trie) MustGet(key []byte) []byte {
109111
res, err := t.Get(key)
110112
if err != nil {
111-
panic(fmt.Errorf("unexpected error in trie.Get: %w", err))
113+
log.Error("Unhandled trie error in Trie.Get", "err", err)
112114
}
113115
return res
114116
}
@@ -162,11 +164,12 @@ func (t *Trie) get(origNode node, key []byte, pos int) (value []byte, newnode no
162164
}
163165
}
164166

165-
// MustGetNode is a wrapper of GetNode and panic if any error is encountered.
167+
// MustGetNode is a wrapper of GetNode and will omit any encountered error but
168+
// just print out an error message.
166169
func (t *Trie) MustGetNode(path []byte) ([]byte, int) {
167170
item, resolved, err := t.GetNode(path)
168171
if err != nil {
169-
panic(fmt.Errorf("unexpected error in tre.GetNode: %w", err))
172+
log.Error("Unhandled trie error in Trie.GetNode", "err", err)
170173
}
171174
return item, resolved
172175
}
@@ -251,11 +254,12 @@ func (t *Trie) getNode(origNode node, path []byte, pos int) (item []byte, newnod
251254
}
252255
}
253256

254-
// MustUpdate is a wrapper of Update and panic if any error is encountered.
257+
// MustUpdate is a wrapper of Update and will omit any encountered error but
258+
// just print out an error message.
255259
func (t *Trie) MustUpdate(key, value []byte) {
256260
err := t.Update(key, value)
257261
if err != nil {
258-
panic(fmt.Errorf("unexpected error in trie.Update: %w", err))
262+
log.Error("Unhandled trie error in Trie.Update", "err", err)
259263
}
260264
}
261265

@@ -370,11 +374,12 @@ func (t *Trie) insert(n node, prefix, key []byte, value node) (bool, node, error
370374
}
371375
}
372376

373-
// MustDelete is a wrapper of Delete and panic if any error is encountered.
377+
// MustDelete is a wrapper of Delete and will omit any encountered error but
378+
// just print out an error message.
374379
func (t *Trie) MustDelete(key []byte) {
375380
err := t.Delete(key)
376381
if err != nil {
377-
panic(fmt.Errorf("unexpected error in trie.Delete: %w", err))
382+
log.Error("Unhandled trie error in Trie.Delete", "err", err)
378383
}
379384
}
380385

0 commit comments

Comments
 (0)