Skip to content

Commit

Permalink
[FAB-2987] Add stacktrace to core/chaincode log msg
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
wlahti committed Sep 21, 2017
1 parent 7f7266d commit 83eb4d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
19 changes: 10 additions & 9 deletions core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func NewChaincodeSupport(getCCEndpoint func() (*pb.PeerEndpoint, error), userrun

ccEndpoint, err := getCCEndpoint()
if err != nil {
chaincodeLogger.Errorf("Error getting chaincode endpoint because %v, using %s", err, peerAddressDefault)
chaincodeLogger.Errorf("Error getting chaincode endpoint using %s: %+v", peerAddressDefault, err)
theChaincodeSupport.peerAddress = peerAddressDefault
} else {
theChaincodeSupport.peerAddress = ccEndpoint.Address
Expand Down Expand Up @@ -325,8 +325,9 @@ func (chaincodeSupport *ChaincodeSupport) sendReady(context context.Context, ccc
var ok bool
if chrte, ok = chaincodeSupport.chaincodeHasBeenLaunched(canName); !ok {
chaincodeSupport.runningChaincodes.Unlock()
chaincodeLogger.Debugf("handler not found for chaincode %s", canName)
return errors.Errorf("handler not found for chaincode %s", canName)
err := errors.Errorf("handler not found for chaincode %s", canName)
chaincodeLogger.Debugf("%+v", err)
return err
}
chaincodeSupport.runningChaincodes.Unlock()

Expand Down Expand Up @@ -532,10 +533,10 @@ func (chaincodeSupport *ChaincodeSupport) launchAndWaitForRegister(ctxt context.
err = errors.Errorf("timeout expired while starting chaincode %s(networkid:%s,peerid:%s,tx:%s)", canName, chaincodeSupport.peerNetworkID, chaincodeSupport.peerID, cccid.TxID)
}
if err != nil {
chaincodeLogger.Debugf("stopping due to error while launching %s", err)
chaincodeLogger.Debugf("stopping due to error while launching: %+v", err)
errIgnore := chaincodeSupport.Stop(ctxt, cccid, cds)
if errIgnore != nil {
chaincodeLogger.Debugf("error on stop %s(%s)", errIgnore, err)
chaincodeLogger.Debugf("stop failed: %+v", errIgnore)
}
}
return err
Expand Down Expand Up @@ -606,8 +607,8 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
if chrte, ok = chaincodeSupport.chaincodeHasBeenLaunched(canName); ok {
if !chrte.handler.registered {
chaincodeSupport.runningChaincodes.Unlock()
chaincodeLogger.Debugf("premature execution - chaincode (%s) launched and waiting for registration", canName)
err = errors.Errorf("premature execution - chaincode (%s) launched and waiting for registration", canName)
chaincodeLogger.Debugf("%+v", err)
return cID, cMsg, err
}
if chrte.handler.isRunning() {
Expand Down Expand Up @@ -692,7 +693,7 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
cLang := cds.ChaincodeSpec.Type
err = chaincodeSupport.launchAndWaitForRegister(context, cccid, cds, cLang, builder)
if err != nil {
chaincodeLogger.Errorf("launchAndWaitForRegister failed %s", err)
chaincodeLogger.Errorf("launchAndWaitForRegister failed: %+v", err)
return cID, cMsg, err
}
}
Expand All @@ -701,11 +702,11 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
//launch will set the chaincode in Ready state
err = chaincodeSupport.sendReady(context, cccid, chaincodeSupport.ccStartupTimeout)
if err != nil {
chaincodeLogger.Errorf("sending init failed(%s)", err)
err = errors.WithMessage(err, "failed to init chaincode")
chaincodeLogger.Errorf("%+v", err)
errIgnore := chaincodeSupport.Stop(context, cccid, cds)
if errIgnore != nil {
chaincodeLogger.Errorf("stop failed %s(%s)", errIgnore, err)
chaincodeLogger.Errorf("stop failed: %+v", errIgnore)
}
}
chaincodeLogger.Debug("sending init completed")
Expand Down
5 changes: 3 additions & 2 deletions core/chaincode/chaincodeexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ func ExecuteChaincode(ctxt context.Context, cccid *ccprovider.CCContext, args []
spec, err = createCIS(cccid.Name, args)
res, ccevent, err = Execute(ctxt, cccid, spec)
if err != nil {
chaincodeLogger.Errorf("Error executing chaincode: %s", err)
return nil, nil, errors.WithMessage(err, "error executing chaincode")
err = errors.WithMessage(err, "error executing chaincode")
chaincodeLogger.Errorf("%+v", err)
return nil, nil, err
}

return res, ccevent, err
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/exectransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func Execute(ctxt context.Context, cccid *ccprovider.CCContext, spec interface{}
func ExecuteWithErrorFilter(ctxt context.Context, cccid *ccprovider.CCContext, spec interface{}) ([]byte, *pb.ChaincodeEvent, error) {
res, event, err := Execute(ctxt, cccid, spec)
if err != nil {
chaincodeLogger.Errorf("ExecuteWithErrorFilter %s error: %s", cccid.Name, err)
chaincodeLogger.Errorf("ExecuteWithErrorFilter %s error: %+v", cccid.Name, err)
return nil, nil, err
}

Expand Down
15 changes: 8 additions & 7 deletions core/chaincode/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (handler *Handler) serialSend(msg *pb.ChaincodeMessage) error {
var err error
if err = handler.ChatStream.Send(msg); err != nil {
err = errors.WithMessage(err, fmt.Sprintf("[%s]Error sending %s", shorttxid(msg.Txid), msg.Type.String()))
chaincodeLogger.Errorf("%s", err)
chaincodeLogger.Errorf("%+v", err)
}
return err
}
Expand Down Expand Up @@ -324,14 +324,14 @@ func (handler *Handler) processStream() error {
case in = <-msgAvail:
// Defer the deregistering of the this handler.
if err == io.EOF {
chaincodeLogger.Debugf("Received EOF, ending chaincode support stream, %s", err)
chaincodeLogger.Debugf("Received EOF, ending chaincode support stream: %+v", err)
return err
} else if err != nil {
chaincodeLogger.Errorf("Error handling chaincode support stream: %s", err)
chaincodeLogger.Errorf("Error handling chaincode support stream: %+v", err)
return err
} else if in == nil {
err = errors.New("received nil message, ending chaincode support stream")
chaincodeLogger.Debug("Received nil message, ending chaincode support stream")
chaincodeLogger.Debug("%+v", err)
return err
}
chaincodeLogger.Debugf("[%s]Received message %s from shim", shorttxid(in.Txid), in.Type.String())
Expand All @@ -352,7 +352,7 @@ func (handler *Handler) processStream() error {
in = nsInfo.msg
if in == nil {
err = errors.New("next state nil message, ending chaincode support stream")
chaincodeLogger.Debug("next state nil message, ending chaincode support stream")
chaincodeLogger.Debug("%+v", err)
return err
}
chaincodeLogger.Debugf("[%s]Move state message %s", shorttxid(in.Txid), in.Type.String())
Expand All @@ -370,8 +370,9 @@ func (handler *Handler) processStream() error {

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

if nsInfo != nil && nsInfo.sendToCC {
Expand Down

0 comments on commit 83eb4d7

Please sign in to comment.