Skip to content

Commit

Permalink
[FAB-5914] Fix error format in chaincode handler
Browse files Browse the repository at this point in the history
This patchset fixes incorrect passing of arguments to a variadic
log function in some error handlers.

It also fixes typo in a error message.

Change-Id: Ia904f3295116d31cbc634834c01ec554fe05bbbe
Signed-off-by: Taku Shimosawa <taku.shimosawa@hal.hitachi.com>
  • Loading branch information
shimos committed Aug 25, 2017
1 parent 01adda9 commit 5809610
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions core/chaincode/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ func (handler *Handler) handleGetStateByRange(msg *pb.ChaincodeMessage) {
handler.deleteQueryIterator(txContext, iterID)
}
payload := []byte(err.Error())
chaincodeLogger.Errorf(errFmt, errArgs)
chaincodeLogger.Errorf(errFmt, errArgs...)
serialSendMsg = &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: msg.Txid}
}

Expand Down Expand Up @@ -835,7 +835,7 @@ func (handler *Handler) handleQueryStateNext(msg *pb.ChaincodeMessage) {
iter.Close()
handler.deleteQueryIterator(txContext, queryStateNext.Id)
}
chaincodeLogger.Errorf(errFmt, errArgs)
chaincodeLogger.Errorf(errFmt, errArgs...)
serialSendMsg = &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: msg.Txid}
}

Expand Down Expand Up @@ -913,7 +913,7 @@ func (handler *Handler) handleQueryStateClose(msg *pb.ChaincodeMessage) {
}()

errHandler := func(payload []byte, errFmt string, errArgs ...interface{}) {
chaincodeLogger.Errorf(errFmt, errArgs)
chaincodeLogger.Errorf(errFmt, errArgs...)
serialSendMsg = &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: msg.Txid}
}

Expand Down Expand Up @@ -993,7 +993,7 @@ func (handler *Handler) handleGetQueryResult(msg *pb.ChaincodeMessage) {
iter.Close()
handler.deleteQueryIterator(txContext, iterID)
}
chaincodeLogger.Errorf(errFmt, errArgs)
chaincodeLogger.Errorf(errFmt, errArgs...)
serialSendMsg = &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: msg.Txid}
}

Expand Down Expand Up @@ -1084,7 +1084,7 @@ func (handler *Handler) handleGetHistoryForKey(msg *pb.ChaincodeMessage) {
iter.Close()
handler.deleteQueryIterator(txContext, iterID)
}
chaincodeLogger.Errorf(errFmt, errArgs)
chaincodeLogger.Errorf(errFmt, errArgs...)
serialSendMsg = &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: msg.Txid}
}

Expand Down Expand Up @@ -1166,7 +1166,7 @@ func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
}

errHandler := func(payload []byte, errFmt string, errArgs ...interface{}) {
chaincodeLogger.Errorf(errFmt, errArgs)
chaincodeLogger.Errorf(errFmt, errArgs...)
triggerNextStateMsg = &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: msg.Txid}
}

Expand Down Expand Up @@ -1259,7 +1259,7 @@ func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
//Call LSCC to get the called chaincode artifacts
cd, err = GetChaincodeDataFromLSCC(ctxt, msg.Txid, txContext.signedProp, txContext.proposal, calledCcIns.ChainID, calledCcIns.ChaincodeName)
if err != nil {
errHandler([]byte(err.Error()), "[%s]Failed to get chaincoed data (%s) for invoked chaincode. Sending %s", shorttxid(msg.Txid), err, pb.ChaincodeMessage_ERROR)
errHandler([]byte(err.Error()), "[%s]Failed to get chaincode data (%s) for invoked chaincode. Sending %s", shorttxid(msg.Txid), err, pb.ChaincodeMessage_ERROR)
return
}

Expand Down
8 changes: 4 additions & 4 deletions core/chaincode/shim/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ func (handler *Handler) handleInit(msg *pb.ChaincodeMessage) {
handler.triggerNextState(nextStateMsg, send)
}()

errFunc := func(err error, payload []byte, ce *pb.ChaincodeEvent, errFmt string, args ...string) *pb.ChaincodeMessage {
errFunc := func(err error, payload []byte, ce *pb.ChaincodeEvent, errFmt string, args ...interface{}) *pb.ChaincodeMessage {
if err != nil {
// Send ERROR message to chaincode support and change state
if payload == nil {
payload = []byte(err.Error())
}
chaincodeLogger.Errorf(errFmt, args)
chaincodeLogger.Errorf(errFmt, args...)
return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: msg.Txid, ChaincodeEvent: ce}
}
return nil
Expand Down Expand Up @@ -290,10 +290,10 @@ func (handler *Handler) handleTransaction(msg *pb.ChaincodeMessage) {
handler.triggerNextState(nextStateMsg, send)
}()

errFunc := func(err error, ce *pb.ChaincodeEvent, errStr string, args ...string) *pb.ChaincodeMessage {
errFunc := func(err error, ce *pb.ChaincodeEvent, errStr string, args ...interface{}) *pb.ChaincodeMessage {
if err != nil {
payload := []byte(err.Error())
chaincodeLogger.Errorf(errStr, args)
chaincodeLogger.Errorf(errStr, args...)
return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: msg.Txid, ChaincodeEvent: ce}
}
return nil
Expand Down

0 comments on commit 5809610

Please sign in to comment.