Skip to content

Commit

Permalink
Rename EndpointError to ErrorDetail (#2974)
Browse files Browse the repository at this point in the history
In the gateway.proto, the EndpointError message has been renamed ErrorDetail.
This commit updates the proto dependency and renames the type in the gateway code.

Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>
  • Loading branch information
andrew-coleman authored Oct 7, 2021
1 parent b52f776 commit 21e4914
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 105 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/hyperledger/fabric-chaincode-go v0.0.0-20201119163726-f8ef75b17719
github.com/hyperledger/fabric-config v0.1.0
github.com/hyperledger/fabric-lib-go v1.0.0
github.com/hyperledger/fabric-protos-go v0.0.0-20210911123859-041d13f0980c
github.com/hyperledger/fabric-protos-go v0.0.0-20211006172752-14f4318ce71c
github.com/kr/pretty v0.2.1
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ github.com/hyperledger/fabric-lib-go v1.0.0 h1:UL1w7c9LvHZUSkIvHTDGklxFv2kTeva1Q
github.com/hyperledger/fabric-lib-go v1.0.0/go.mod h1:H362nMlunurmHwkYqR5uHL2UDWbQdbfz74n8kbCFsqc=
github.com/hyperledger/fabric-protos-go v0.0.0-20190919234611-2a87503ac7c9/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/hyperledger/fabric-protos-go v0.0.0-20200424173316-dd554ba3746e/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/hyperledger/fabric-protos-go v0.0.0-20210911123859-041d13f0980c h1:QPhSriw6EzMOj/d7gcGiKEvozVvQ5HLk9UWie4KAvSs=
github.com/hyperledger/fabric-protos-go v0.0.0-20210911123859-041d13f0980c/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/hyperledger/fabric-protos-go v0.0.0-20211006172752-14f4318ce71c h1:kbXDwJfMliHxkIF+wQu0PgS7MlrhoQi7TzAKd28Iaes=
github.com/hyperledger/fabric-protos-go v0.0.0-20211006172752-14f4318ce71c/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
Expand Down
16 changes: 8 additions & 8 deletions internal/pkg/gateway/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

type endorserResponse struct {
pr *peer.ProposalResponse
err *gp.EndpointError
err *gp.ErrorDetail
}

// Evaluate will invoke the transaction function as specified in the SignedProposal
Expand Down Expand Up @@ -67,14 +67,14 @@ func (gs *Server) Evaluate(ctx context.Context, request *gp.EvaluateRequest) (*g
response, err := endorser.client.ProcessProposal(ctx, signedProposal)
if err != nil {
logger.Debugw("Evaluate call to endorser failed", "chaincode", chaincodeID, "channel", channel, "txid", request.TransactionId, "endorserAddress", endorser.endpointConfig.address, "endorserMspid", endorser.endpointConfig.mspid, "error", err)
return nil, wrappedRpcError(err, "failed to evaluate transaction", endpointError(endorser.endpointConfig, err))
return nil, wrappedRpcError(err, "failed to evaluate transaction", errorDetail(endorser.endpointConfig, err))
}

rr := response.GetResponse()
if rr != nil && (rr.Status < 200 || rr.Status >= 400) {
logger.Debugw("Evaluate call to endorser returned a malformed or error response", "chaincode", chaincodeID, "channel", channel, "txid", request.TransactionId, "endorserAddress", endorser.endpointConfig.address, "endorserMspid", endorser.endpointConfig.mspid, "status", rr.Status, "message", rr.Message)
err = fmt.Errorf("error %d returned from chaincode %s on channel %s: %s", rr.Status, chaincodeID, channel, rr.Message)
return nil, rpcError(codes.Unknown, "error returned from chaincode: "+rr.Message, endpointError(endorser.endpointConfig, err))
return nil, rpcError(codes.Unknown, "error returned from chaincode: "+rr.Message, errorDetail(endorser.endpointConfig, err))
}

evaluateResponse := &gp.EvaluateResponse{
Expand Down Expand Up @@ -152,11 +152,11 @@ func (gs *Server) Endorse(ctx context.Context, request *gp.EndorseRequest) (*gp.
// 2. Process the proposal on this endorser
firstResponse, err := firstEndorser.client.ProcessProposal(ctx, signedProposal)
if err != nil {
return nil, wrappedRpcError(err, "failed to endorse transaction", endpointError(firstEndorser.endpointConfig, err))
return nil, wrappedRpcError(err, "failed to endorse transaction", errorDetail(firstEndorser.endpointConfig, err))
}
if firstResponse.Response.Status < 200 || firstResponse.Response.Status >= 400 {
err := fmt.Errorf("error %d, %s", firstResponse.Response.Status, firstResponse.Response.Message)
endpointErr := endpointError(firstEndorser.endpointConfig, err)
endpointErr := errorDetail(firstEndorser.endpointConfig, err)
errorMessage := "failed to endorse transaction: " + detailsAsString(endpointErr)
return nil, rpcError(codes.Aborted, errorMessage, endpointErr)
}
Expand Down Expand Up @@ -216,11 +216,11 @@ func (gs *Server) Endorse(ctx context.Context, request *gp.EndorseRequest) (*gp.
switch {
case err != nil:
logger.Debugw("Endorse call to endorser failed", "channel", request.ChannelId, "txid", request.TransactionId, "numEndorsers", len(endorsers), "endorserAddress", e.endpointConfig.address, "endorserMspid", e.endpointConfig.mspid, "error", err)
responseCh <- &endorserResponse{err: endpointError(e.endpointConfig, err)}
responseCh <- &endorserResponse{err: errorDetail(e.endpointConfig, err)}
case response.Response.Status < 200 || response.Response.Status >= 400:
// this is an error case and will be returned in the error details to the client
logger.Debugw("Endorse call to endorser returned failure", "channel", request.ChannelId, "txid", request.TransactionId, "numEndorsers", len(endorsers), "endorserAddress", e.endpointConfig.address, "endorserMspid", e.endpointConfig.mspid, "status", response.Response.Status, "message", response.Response.Message)
responseCh <- &endorserResponse{err: endpointError(e.endpointConfig, fmt.Errorf("error %d, %s", response.Response.Status, response.Response.Message))}
responseCh <- &endorserResponse{err: errorDetail(e.endpointConfig, fmt.Errorf("error %d, %s", response.Response.Status, response.Response.Message))}
default:
logger.Debugw("Endorse call to endorser returned success", "channel", request.ChannelId, "txid", request.TransactionId, "numEndorsers", len(endorsers), "endorserAddress", e.endpointConfig.address, "endorserMspid", e.endpointConfig.mspid, "status", response.Response.Status, "message", response.Response.Message)
responseCh <- &endorserResponse{pr: response}
Expand Down Expand Up @@ -288,7 +288,7 @@ func (gs *Server) Submit(ctx context.Context, request *gp.SubmitRequest) (*gp.Su
return &gp.SubmitResponse{}, nil
}
logger.Warnw("Error sending transaction to orderer", "TxID", request.TransactionId, "endpoint", orderer.address, "err", err)
errDetails = append(errDetails, endpointError(orderer.endpointConfig, err))
errDetails = append(errDetails, errorDetail(orderer.endpointConfig, err))
}

return nil, rpcError(codes.Aborted, "no orderers could successfully process transaction", errDetails...)
Expand Down
28 changes: 14 additions & 14 deletions internal/pkg/gateway/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type testDef struct {
identity []byte
localResponse string
errString string
errDetails []*pb.EndpointError
errDetails []*pb.ErrorDetail
endpointDefinition *endpointDef
endorsingOrgs []string
postSetup func(t *testing.T, def *preparedTest)
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestEvaluate(t *testing.T) {
proposalError: status.Error(codes.Aborted, "wibble"),
},
errString: "rpc error: code = Aborted desc = failed to evaluate transaction: wibble",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "localhost:7051",
MspId: "msp1",
Message: "rpc error: code = Aborted desc = wibble",
Expand All @@ -310,7 +310,7 @@ func TestEvaluate(t *testing.T) {
proposalResponseMessage: "Mock chaincode error",
},
errString: "rpc error: code = Unknown desc = error returned from chaincode: Mock chaincode error",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "peer1:8051",
MspId: "msp1",
Message: "error 400 returned from chaincode test_chaincode on channel test_channel: Mock chaincode error",
Expand Down Expand Up @@ -592,7 +592,7 @@ func TestEndorse(t *testing.T) {
proposalError: status.Error(codes.Aborted, "wibble"),
},
errString: "rpc error: code = Aborted desc = failed to endorse transaction: wibble",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "localhost:7051",
MspId: "msp1",
Message: "rpc error: code = Aborted desc = wibble",
Expand All @@ -611,7 +611,7 @@ func TestEndorse(t *testing.T) {
def.localEndorser.ProcessProposalReturns(createProposalResponse(t, localhostMock.address, "all_good", 200, ""), nil)
},
errString: "rpc error: code = Aborted desc = failed to endorse transaction: [{address:\"peer4:11051\" msp_id:\"msp3\" message:\"rpc error: code = Aborted desc = remote-wobble\" }]",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "peer4:11051",
MspId: "msp3",
Message: "rpc error: code = Aborted desc = remote-wobble",
Expand All @@ -627,7 +627,7 @@ func TestEndorse(t *testing.T) {
proposalResponseMessage: "Mock chaincode error",
},
errString: "rpc error: code = Aborted desc = failed to endorse transaction: [{address:\"localhost:7051\" msp_id:\"msp1\" message:\"error 400, Mock chaincode error\" }]",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "localhost:7051",
MspId: "msp1",
Message: "error 400, Mock chaincode error",
Expand All @@ -647,7 +647,7 @@ func TestEndorse(t *testing.T) {
def.localEndorser.ProcessProposalReturns(createProposalResponse(t, localhostMock.address, "all_good", 200, ""), nil)
},
errString: "rpc error: code = Aborted desc = failed to endorse transaction: [{address:\"peer4:11051\" msp_id:\"msp3\" message:\"error 400, Mock chaincode error\" }]",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "peer4:11051",
MspId: "msp3",
Message: "error 400, Mock chaincode error",
Expand Down Expand Up @@ -737,7 +737,7 @@ func TestSubmit(t *testing.T) {
ordererBroadcastError: status.Error(codes.FailedPrecondition, "Orderer not listening!"),
},
errString: "rpc error: code = Aborted desc = no orderers could successfully process transaction",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "orderer:7050",
MspId: "msp1",
Message: "failed to create BroadcastClient: rpc error: code = FailedPrecondition desc = Orderer not listening!",
Expand All @@ -753,7 +753,7 @@ func TestSubmit(t *testing.T) {
ordererSendError: status.Error(codes.Internal, "Orderer says no!"),
},
errString: "rpc error: code = Aborted desc = no orderers could successfully process transaction",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "orderer:7050",
MspId: "msp1",
Message: "failed to send transaction to orderer: rpc error: code = Internal desc = Orderer says no!",
Expand All @@ -769,7 +769,7 @@ func TestSubmit(t *testing.T) {
ordererRecvError: status.Error(codes.FailedPrecondition, "Orderer not happy!"),
},
errString: "rpc error: code = Aborted desc = no orderers could successfully process transaction",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "orderer:7050",
MspId: "msp1",
Message: "failed to receive response from orderer: rpc error: code = FailedPrecondition desc = Orderer not happy!",
Expand All @@ -790,7 +790,7 @@ func TestSubmit(t *testing.T) {
}
},
errString: "rpc error: code = Aborted desc = no orderers could successfully process transaction",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "orderer:7050",
MspId: "msp1",
Message: "received nil response from orderer",
Expand All @@ -814,7 +814,7 @@ func TestSubmit(t *testing.T) {
}
},
errString: "rpc error: code = Aborted desc = no orderers could successfully process transaction",
errDetails: []*pb.EndpointError{{
errDetails: []*pb.ErrorDetail{{
Address: "orderer:7050",
MspId: "msp1",
Message: "received unsuccessful response from orderer: " + cp.Status_name[int32(cp.Status_BAD_REQUEST)],
Expand Down Expand Up @@ -907,7 +907,7 @@ func TestSubmit(t *testing.T) {
ordererBroadcastError: status.Error(codes.FailedPrecondition, "Orderer not listening!"),
},
errString: "rpc error: code = Aborted desc = no orderers could successfully process transaction",
errDetails: []*pb.EndpointError{
errDetails: []*pb.ErrorDetail{
{
Address: "orderer1:7050",
MspId: "msp1",
Expand Down Expand Up @@ -1601,7 +1601,7 @@ func prepareTest(t *testing.T, tt *testDef) *preparedTest {
return pt
}

func checkError(t *testing.T, err error, errString string, details []*pb.EndpointError) {
func checkError(t *testing.T, err error, errString string, details []*pb.ErrorDetail) {
require.EqualError(t, err, errString)
s, ok := status.FromError(err)
require.True(t, ok, "Expected a gRPC status error")
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/gateway/apiutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func wrappedRpcError(err error, message string, details ...proto.Message) error
return rpcError(statusErr.Code(), message+": "+statusErr.Message(), details...)
}

func endpointError(e *endpointConfig, err error) *gp.EndpointError {
return &gp.EndpointError{Address: e.address, MspId: e.mspid, Message: err.Error()}
func errorDetail(e *endpointConfig, err error) *gp.ErrorDetail {
return &gp.ErrorDetail{Address: e.address, MspId: e.mspid, Message: err.Error()}
}

func detailsAsString(details ...proto.Message) string {
Expand Down
Loading

0 comments on commit 21e4914

Please sign in to comment.