Skip to content

Commit 83eb4d7

Browse files
committed
[FAB-2987] Add stacktrace to core/chaincode log msg
This CR formats logger messages that print error details using %+v to ensure the stack trace is included. Change-Id: I352a024c25bd1229153f5be95cba26eba14cbbf1 Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
1 parent 7f7266d commit 83eb4d7

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

core/chaincode/chaincode_support.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func NewChaincodeSupport(getCCEndpoint func() (*pb.PeerEndpoint, error), userrun
153153

154154
ccEndpoint, err := getCCEndpoint()
155155
if err != nil {
156-
chaincodeLogger.Errorf("Error getting chaincode endpoint because %v, using %s", err, peerAddressDefault)
156+
chaincodeLogger.Errorf("Error getting chaincode endpoint using %s: %+v", peerAddressDefault, err)
157157
theChaincodeSupport.peerAddress = peerAddressDefault
158158
} else {
159159
theChaincodeSupport.peerAddress = ccEndpoint.Address
@@ -325,8 +325,9 @@ func (chaincodeSupport *ChaincodeSupport) sendReady(context context.Context, ccc
325325
var ok bool
326326
if chrte, ok = chaincodeSupport.chaincodeHasBeenLaunched(canName); !ok {
327327
chaincodeSupport.runningChaincodes.Unlock()
328-
chaincodeLogger.Debugf("handler not found for chaincode %s", canName)
329-
return errors.Errorf("handler not found for chaincode %s", canName)
328+
err := errors.Errorf("handler not found for chaincode %s", canName)
329+
chaincodeLogger.Debugf("%+v", err)
330+
return err
330331
}
331332
chaincodeSupport.runningChaincodes.Unlock()
332333

@@ -532,10 +533,10 @@ func (chaincodeSupport *ChaincodeSupport) launchAndWaitForRegister(ctxt context.
532533
err = errors.Errorf("timeout expired while starting chaincode %s(networkid:%s,peerid:%s,tx:%s)", canName, chaincodeSupport.peerNetworkID, chaincodeSupport.peerID, cccid.TxID)
533534
}
534535
if err != nil {
535-
chaincodeLogger.Debugf("stopping due to error while launching %s", err)
536+
chaincodeLogger.Debugf("stopping due to error while launching: %+v", err)
536537
errIgnore := chaincodeSupport.Stop(ctxt, cccid, cds)
537538
if errIgnore != nil {
538-
chaincodeLogger.Debugf("error on stop %s(%s)", errIgnore, err)
539+
chaincodeLogger.Debugf("stop failed: %+v", errIgnore)
539540
}
540541
}
541542
return err
@@ -606,8 +607,8 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
606607
if chrte, ok = chaincodeSupport.chaincodeHasBeenLaunched(canName); ok {
607608
if !chrte.handler.registered {
608609
chaincodeSupport.runningChaincodes.Unlock()
609-
chaincodeLogger.Debugf("premature execution - chaincode (%s) launched and waiting for registration", canName)
610610
err = errors.Errorf("premature execution - chaincode (%s) launched and waiting for registration", canName)
611+
chaincodeLogger.Debugf("%+v", err)
611612
return cID, cMsg, err
612613
}
613614
if chrte.handler.isRunning() {
@@ -692,7 +693,7 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
692693
cLang := cds.ChaincodeSpec.Type
693694
err = chaincodeSupport.launchAndWaitForRegister(context, cccid, cds, cLang, builder)
694695
if err != nil {
695-
chaincodeLogger.Errorf("launchAndWaitForRegister failed %s", err)
696+
chaincodeLogger.Errorf("launchAndWaitForRegister failed: %+v", err)
696697
return cID, cMsg, err
697698
}
698699
}
@@ -701,11 +702,11 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
701702
//launch will set the chaincode in Ready state
702703
err = chaincodeSupport.sendReady(context, cccid, chaincodeSupport.ccStartupTimeout)
703704
if err != nil {
704-
chaincodeLogger.Errorf("sending init failed(%s)", err)
705705
err = errors.WithMessage(err, "failed to init chaincode")
706+
chaincodeLogger.Errorf("%+v", err)
706707
errIgnore := chaincodeSupport.Stop(context, cccid, cds)
707708
if errIgnore != nil {
708-
chaincodeLogger.Errorf("stop failed %s(%s)", errIgnore, err)
709+
chaincodeLogger.Errorf("stop failed: %+v", errIgnore)
709710
}
710711
}
711712
chaincodeLogger.Debug("sending init completed")

core/chaincode/chaincodeexec.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ func ExecuteChaincode(ctxt context.Context, cccid *ccprovider.CCContext, args []
8484
spec, err = createCIS(cccid.Name, args)
8585
res, ccevent, err = Execute(ctxt, cccid, spec)
8686
if err != nil {
87-
chaincodeLogger.Errorf("Error executing chaincode: %s", err)
88-
return nil, nil, errors.WithMessage(err, "error executing chaincode")
87+
err = errors.WithMessage(err, "error executing chaincode")
88+
chaincodeLogger.Errorf("%+v", err)
89+
return nil, nil, err
8990
}
9091

9192
return res, ccevent, err

core/chaincode/exectransaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func Execute(ctxt context.Context, cccid *ccprovider.CCContext, spec interface{}
9292
func ExecuteWithErrorFilter(ctxt context.Context, cccid *ccprovider.CCContext, spec interface{}) ([]byte, *pb.ChaincodeEvent, error) {
9393
res, event, err := Execute(ctxt, cccid, spec)
9494
if err != nil {
95-
chaincodeLogger.Errorf("ExecuteWithErrorFilter %s error: %s", cccid.Name, err)
95+
chaincodeLogger.Errorf("ExecuteWithErrorFilter %s error: %+v", cccid.Name, err)
9696
return nil, nil, err
9797
}
9898

core/chaincode/handler.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (handler *Handler) serialSend(msg *pb.ChaincodeMessage) error {
163163
var err error
164164
if err = handler.ChatStream.Send(msg); err != nil {
165165
err = errors.WithMessage(err, fmt.Sprintf("[%s]Error sending %s", shorttxid(msg.Txid), msg.Type.String()))
166-
chaincodeLogger.Errorf("%s", err)
166+
chaincodeLogger.Errorf("%+v", err)
167167
}
168168
return err
169169
}
@@ -324,14 +324,14 @@ func (handler *Handler) processStream() error {
324324
case in = <-msgAvail:
325325
// Defer the deregistering of the this handler.
326326
if err == io.EOF {
327-
chaincodeLogger.Debugf("Received EOF, ending chaincode support stream, %s", err)
327+
chaincodeLogger.Debugf("Received EOF, ending chaincode support stream: %+v", err)
328328
return err
329329
} else if err != nil {
330-
chaincodeLogger.Errorf("Error handling chaincode support stream: %s", err)
330+
chaincodeLogger.Errorf("Error handling chaincode support stream: %+v", err)
331331
return err
332332
} else if in == nil {
333333
err = errors.New("received nil message, ending chaincode support stream")
334-
chaincodeLogger.Debug("Received nil message, ending chaincode support stream")
334+
chaincodeLogger.Debug("%+v", err)
335335
return err
336336
}
337337
chaincodeLogger.Debugf("[%s]Received message %s from shim", shorttxid(in.Txid), in.Type.String())
@@ -352,7 +352,7 @@ func (handler *Handler) processStream() error {
352352
in = nsInfo.msg
353353
if in == nil {
354354
err = errors.New("next state nil message, ending chaincode support stream")
355-
chaincodeLogger.Debug("next state nil message, ending chaincode support stream")
355+
chaincodeLogger.Debug("%+v", err)
356356
return err
357357
}
358358
chaincodeLogger.Debugf("[%s]Move state message %s", shorttxid(in.Txid), in.Type.String())
@@ -370,8 +370,9 @@ func (handler *Handler) processStream() error {
370370

371371
err = handler.HandleMessage(in)
372372
if err != nil {
373-
chaincodeLogger.Errorf("[%s]error handling message, ending stream: %s", shorttxid(in.Txid), err)
374-
return errors.WithMessage(err, "error handling message, ending stream")
373+
err = errors.WithMessage(err, "error handling message, ending stream")
374+
chaincodeLogger.Errorf("[%s] %+v", shorttxid(in.Txid), err)
375+
return err
375376
}
376377

377378
if nsInfo != nil && nsInfo.sendToCC {

0 commit comments

Comments
 (0)