@@ -19,7 +19,6 @@ limitations under the License.
19
19
package shim
20
20
21
21
import (
22
- "errors"
23
22
"flag"
24
23
"fmt"
25
24
"io"
@@ -37,6 +36,7 @@ import (
37
36
pb "github.com/hyperledger/fabric/protos/peer"
38
37
"github.com/hyperledger/fabric/protos/utils"
39
38
"github.com/op/go-logging"
39
+ "github.com/pkg/errors"
40
40
"github.com/spf13/viper"
41
41
"golang.org/x/net/context"
42
42
"google.golang.org/grpc"
@@ -100,7 +100,7 @@ func userChaincodeStreamGetter(name string) (PeerChaincodeStream, error) {
100
100
clientConn , err := newPeerClientConnection ()
101
101
if err != nil {
102
102
chaincodeLogger .Errorf ("Error trying to connect to local peer: %s" , err )
103
- return nil , fmt . Errorf ( "Error trying to connect to local peer: %s" , err )
103
+ return nil , errors . Wrap ( err , "error trying to connect to local peer" )
104
104
}
105
105
106
106
chaincodeLogger .Debugf ("os.Args returns: %s" , os .Args )
@@ -110,7 +110,7 @@ func userChaincodeStreamGetter(name string) (PeerChaincodeStream, error) {
110
110
// Establish stream with validating peer
111
111
stream , err := chaincodeSupportClient .Register (context .Background ())
112
112
if err != nil {
113
- return nil , fmt .Errorf ( "Error chatting with leader at address=%s: %s " , getPeerAddress (), err )
113
+ return nil , errors . WithMessage ( err , fmt .Sprintf ( "error chatting with leader at address=%s" , getPeerAddress ()) )
114
114
}
115
115
116
116
return stream , nil
@@ -124,12 +124,12 @@ func Start(cc Chaincode) error {
124
124
125
125
chaincodename := viper .GetString ("chaincode.id.name" )
126
126
if chaincodename == "" {
127
- return fmt . Errorf ( "Error chaincode id not provided" )
127
+ return errors . New ( "error chaincode id not provided" )
128
128
}
129
129
130
130
err := factory .InitFactories (factory .GetDefaultOpts ())
131
131
if err != nil {
132
- return fmt . Errorf ( "Internal error, BCCSP could not be initialized with default options: %s" , err )
132
+ return errors . WithMessage ( err , "internal error, BCCSP could not be initialized with default options" )
133
133
}
134
134
135
135
//mock stream not set up ... get real stream
@@ -216,7 +216,7 @@ func StartInProc(env []string, args []string, cc Chaincode, recv <-chan *pb.Chai
216
216
}
217
217
}
218
218
if chaincodename == "" {
219
- return fmt . Errorf ( "Error chaincode id not provided" )
219
+ return errors . New ( "error chaincode id not provided" )
220
220
}
221
221
222
222
stream := newInProcStream (recv , send )
@@ -255,12 +255,12 @@ func chatWithPeer(chaincodename string, stream PeerChaincodeStream, cc Chaincode
255
255
chaincodeID := & pb.ChaincodeID {Name : chaincodename }
256
256
payload , err := proto .Marshal (chaincodeID )
257
257
if err != nil {
258
- return fmt . Errorf ( "Error marshalling chaincodeID during chaincode registration: %s" , err )
258
+ return errors . Wrap ( err , "error marshalling chaincodeID during chaincode registration" )
259
259
}
260
260
// Register on the stream
261
261
chaincodeLogger .Debugf ("Registering.. sending %s" , pb .ChaincodeMessage_REGISTER )
262
262
if err = handler .serialSend (& pb.ChaincodeMessage {Type : pb .ChaincodeMessage_REGISTER , Payload : payload }); err != nil {
263
- return fmt . Errorf ( "Error sending chaincode REGISTER: %s" , err )
263
+ return errors . WithMessage ( err , "error sending chaincode REGISTER" )
264
264
}
265
265
waitc := make (chan struct {})
266
266
errc := make (chan error )
@@ -289,7 +289,7 @@ func chatWithPeer(chaincodename string, stream PeerChaincodeStream, cc Chaincode
289
289
continue
290
290
}
291
291
//no, bail
292
- err = fmt .Errorf ( "Error sending %s: %s " , in .Type .String (), sendErr )
292
+ err = errors . Wrap ( sendErr , fmt .Sprintf ( "error sending %s" , in .Type .String ()) )
293
293
return
294
294
case in = <- msgAvail :
295
295
if err == io .EOF {
@@ -299,7 +299,7 @@ func chatWithPeer(chaincodename string, stream PeerChaincodeStream, cc Chaincode
299
299
chaincodeLogger .Errorf ("Received error from server: %s, ending chaincode stream" , err )
300
300
return
301
301
} else if in == nil {
302
- err = fmt . Errorf ( "Received nil message, ending chaincode stream" )
302
+ err = errors . New ( "received nil message, ending chaincode stream" )
303
303
chaincodeLogger .Debug ("Received nil message, ending chaincode stream" )
304
304
return
305
305
}
@@ -316,7 +316,7 @@ func chatWithPeer(chaincodename string, stream PeerChaincodeStream, cc Chaincode
316
316
// Call FSM.handleMessage()
317
317
err = handler .handleMessage (in )
318
318
if err != nil {
319
- err = fmt . Errorf ( "Error handling message: %s" , err )
319
+ err = errors . WithMessage ( err , "error handling message" )
320
320
return
321
321
}
322
322
@@ -353,18 +353,18 @@ func (stub *ChaincodeStub) init(handler *Handler, txid string, input *pb.Chainco
353
353
354
354
stub .proposal , err = utils .GetProposal (signedProposal .ProposalBytes )
355
355
if err != nil {
356
- return fmt . Errorf ( "Failed extracting signedProposal from signed signedProposal. [%s]" , err )
356
+ return errors . WithMessage ( err , "failed extracting signedProposal from signed signedProposal" )
357
357
}
358
358
359
359
// Extract creator, transient, binding...
360
360
stub .creator , stub .transient , err = utils .GetChaincodeProposalContext (stub .proposal )
361
361
if err != nil {
362
- return fmt . Errorf ( "Failed extracting signedProposal fields. [%s]" , err )
362
+ return errors . WithMessage ( err , "failed extracting signedProposal fields" )
363
363
}
364
364
365
365
stub .binding , err = utils .ComputeProposalBinding (stub .proposal )
366
366
if err != nil {
367
- return fmt . Errorf ( "Failed computing binding from signedProposal. [%s]" , err )
367
+ return errors . WithMessage ( err , "failed computing binding from signedProposal" )
368
368
}
369
369
}
370
370
@@ -404,7 +404,7 @@ func (stub *ChaincodeStub) GetState(key string) ([]byte, error) {
404
404
// PutState documentation can be found in interfaces.go
405
405
func (stub * ChaincodeStub ) PutState (key string , value []byte ) error {
406
406
if key == "" {
407
- return fmt . Errorf ("key must not be an empty string" )
407
+ return errors . New ("key must not be an empty string" )
408
408
}
409
409
return stub .handler .handlePutState (key , value , stub .TxID )
410
410
}
@@ -514,11 +514,11 @@ func splitCompositeKey(compositeKey string) (string, []string, error) {
514
514
515
515
func validateCompositeKeyAttribute (str string ) error {
516
516
if ! utf8 .ValidString (str ) {
517
- return fmt .Errorf ("Not a valid utf8 string: [%x]" , str )
517
+ return errors .Errorf ("not a valid utf8 string: [%x]" , str )
518
518
}
519
519
for index , runeValue := range str {
520
520
if runeValue == minUnicodeRuneValue || runeValue == maxUnicodeRuneValue {
521
- return fmt .Errorf (`Input contain unicode %#U starting at position [%d]. %#U and %#U are not allowed in the input attribute of a composite key` ,
521
+ return errors .Errorf (`input contain unicode %#U starting at position [%d]. %#U and %#U are not allowed in the input attribute of a composite key` ,
522
522
runeValue , index , minUnicodeRuneValue , maxUnicodeRuneValue )
523
523
}
524
524
}
@@ -532,7 +532,7 @@ func validateCompositeKeyAttribute(str string) error {
532
532
func validateSimpleKeys (simpleKeys ... string ) error {
533
533
for _ , key := range simpleKeys {
534
534
if len (key ) > 0 && key [0 ] == compositeKeyNamespace [0 ] {
535
- return fmt .Errorf (`First character of the key [%s] contains a null character which is not allowed` , key )
535
+ return errors .Errorf (`first character of the key [%s] contains a null character which is not allowed` , key )
536
536
}
537
537
}
538
538
return nil
@@ -597,7 +597,7 @@ func (iter *CommonIterator) getResultFromBytes(queryResultBytes *pb.QueryResultB
597
597
}
598
598
return historyQueryResult , nil
599
599
}
600
- return nil , errors .New ("Wrong result type" )
600
+ return nil , errors .New ("wrong result type" )
601
601
}
602
602
603
603
func (iter * CommonIterator ) fetchNextQueryResult () error {
@@ -634,12 +634,12 @@ func (iter *CommonIterator) nextResult(rType resultType) (commonledger.QueryResu
634
634
return queryResult , err
635
635
} else if ! iter .response .HasMore {
636
636
// On call to Next() without check of HasMore
637
- return nil , errors .New ("No such key" )
637
+ return nil , errors .New ("no such key" )
638
638
}
639
639
640
640
// should not fall through here
641
641
// case: no cached results but HasMore is true.
642
- return nil , errors .New ("Invalid iterator state" )
642
+ return nil , errors .New ("invalid iterator state" )
643
643
}
644
644
645
645
// Close documentation can be found in interfaces.go
@@ -724,7 +724,7 @@ func (stub *ChaincodeStub) GetTxTimestamp() (*timestamp.Timestamp, error) {
724
724
// SetEvent documentation can be found in interfaces.go
725
725
func (stub * ChaincodeStub ) SetEvent (name string , payload []byte ) error {
726
726
if name == "" {
727
- return errors .New ("Event name can not be nil string. " )
727
+ return errors .New ("event name can not be nil string" )
728
728
}
729
729
stub .chaincodeEvent = & pb.ChaincodeEvent {EventName : name , Payload : payload }
730
730
return nil
0 commit comments