@@ -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.
108110func (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.
166169func (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.
255259func (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.
374379func (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