@@ -12,9 +12,9 @@ import (
1212 "path/filepath"
1313 "unicode/utf8"
1414
15+ "github.com/cockroachdb/errors"
1516 "github.com/hyperledger/fabric-protos-go-apiv2/common"
1617 "github.com/hyperledger/fabric-protos-go-apiv2/peer"
17- "github.com/pkg/errors"
1818 "google.golang.org/protobuf/encoding/protowire"
1919 "google.golang.org/protobuf/proto"
2020
@@ -36,6 +36,9 @@ const (
3636 snapshotMetadataFileName = "txids.metadata"
3737)
3838
39+ // ErrNotFound is returned when a requested item is not found in the block index.
40+ var ErrNotFound = errors .New ("not found in index" )
41+
3942var (
4043 indexSavePointKey = []byte (indexSavePointKeyStr )
4144 errIndexSavePointKeyNotPresent = errors .New ("NoBlockIndexed" )
@@ -157,7 +160,7 @@ func (index *blockIndex) getBlockLocByHash(blockHash []byte) (*fileLocPointer, e
157160 return nil , err
158161 }
159162 if b == nil {
160- return nil , errors .Errorf ( "no such block hash [%x] in index " , blockHash )
163+ return nil , errors .Wrapf ( ErrNotFound , " block hash [%x]" , blockHash )
161164 }
162165 blkLoc := & fileLocPointer {}
163166 if err := blkLoc .unmarshal (b ); err != nil {
@@ -175,7 +178,7 @@ func (index *blockIndex) getBlockLocByBlockNum(blockNum uint64) (*fileLocPointer
175178 return nil , err
176179 }
177180 if b == nil {
178- return nil , errors .Errorf ( "no such block number [%d] in index " , blockNum )
181+ return nil , errors .Wrapf ( ErrNotFound , " block number [%d]" , blockNum )
179182 }
180183 blkLoc := & fileLocPointer {}
181184 if err := blkLoc .unmarshal (b ); err != nil {
@@ -250,7 +253,7 @@ func (index *blockIndex) getTxIDVal(txID string) (*TxIDIndexValue, uint64, error
250253 return nil , 0 , errors .Wrapf (err , "error while trying to retrieve transaction info by TXID [%s]" , txID )
251254 }
252255 if ! present {
253- return nil , 0 , errors .Errorf ( "no such transaction ID [%s] in index " , txID )
256+ return nil , 0 , errors .Wrapf ( ErrNotFound , " transaction ID [%s]" , txID )
254257 }
255258 valBytes := itr .Value ()
256259 if len (valBytes ) == 0 {
@@ -276,7 +279,7 @@ func (index *blockIndex) getTXLocByBlockNumTranNum(blockNum uint64, tranNum uint
276279 return nil , err
277280 }
278281 if b == nil {
279- return nil , errors .Errorf ( "no such blockNumber, transactionNumber <%d, %d> in index " , blockNum , tranNum )
282+ return nil , errors .Wrapf ( ErrNotFound , " blockNumber, transactionNumber <%d, %d>" , blockNum , tranNum )
280283 }
281284 txFLP := & fileLocPointer {}
282285 if err := txFLP .unmarshal (b ); err != nil {
@@ -358,7 +361,8 @@ func (index *blockIndex) exportUniqueTxIDs(dir string, newHashFunc snapshot.NewH
358361func importTxIDsFromSnapshot (
359362 snapshotDir string ,
360363 lastBlockNumInSnapshot uint64 ,
361- db * leveldbhelper.DBHandle ) error {
364+ db * leveldbhelper.DBHandle ,
365+ ) error {
362366 txIDsMetadata , err := snapshot .OpenFile (filepath .Join (snapshotDir , snapshotMetadataFileName ), snapshotFileFormat )
363367 if err != nil {
364368 return err
0 commit comments