Skip to content

Commit d244e5d

Browse files
committed
[FAB-9973] Chaincode cmd errors return wrong cc name
Include the actual chaincode name in the error messages returned by the install, instantiate, package and upgrade commands. Also properly format error strings in the enclosing functions. Change-Id: I02ac905e6b330e0668a630165cc1227208232b93 Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent f1133ad commit d244e5d

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

peer/chaincode/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func genChaincodeDeploymentSpec(cmd *cobra.Command, chaincodeName, chaincodeVers
103103

104104
cds, err := getChaincodeDeploymentSpec(spec, true)
105105
if err != nil {
106-
return nil, fmt.Errorf("Error getting chaincode code %s: %s", chainFuncName, err)
106+
return nil, fmt.Errorf("error getting chaincode code %s: %s", chaincodeName, err)
107107
}
108108

109109
return cds, nil

peer/chaincode/instantiate.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,36 @@ func instantiate(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envel
6262

6363
cds, err := getChaincodeDeploymentSpec(spec, false)
6464
if err != nil {
65-
return nil, fmt.Errorf("Error getting chaincode code %s: %s", chainFuncName, err)
65+
return nil, fmt.Errorf("error getting chaincode code %s: %s", chaincodeName, err)
6666
}
6767

6868
creator, err := cf.Signer.Serialize()
6969
if err != nil {
70-
return nil, fmt.Errorf("Error serializing identity for %s: %s", cf.Signer.GetIdentifier(), err)
70+
return nil, fmt.Errorf("error serializing identity for %s: %s", cf.Signer.GetIdentifier(), err)
7171
}
7272

7373
prop, _, err := utils.CreateDeployProposalFromCDS(channelID, cds, creator, policyMarshalled, []byte(escc), []byte(vscc), collectionConfigBytes)
7474
if err != nil {
75-
return nil, fmt.Errorf("Error creating proposal %s: %s", chainFuncName, err)
75+
return nil, fmt.Errorf("error creating proposal %s: %s", chainFuncName, err)
7676
}
7777

7878
var signedProp *pb.SignedProposal
7979
signedProp, err = utils.GetSignedProposal(prop, cf.Signer)
8080
if err != nil {
81-
return nil, fmt.Errorf("Error creating signed proposal %s: %s", chainFuncName, err)
81+
return nil, fmt.Errorf("error creating signed proposal %s: %s", chainFuncName, err)
8282
}
8383

8484
// instantiate is currently only supported for one peer
8585
proposalResponse, err := cf.EndorserClients[0].ProcessProposal(context.Background(), signedProp)
8686
if err != nil {
87-
return nil, fmt.Errorf("Error endorsing %s: %s", chainFuncName, err)
87+
return nil, fmt.Errorf("error endorsing %s: %s", chainFuncName, err)
8888
}
8989

9090
if proposalResponse != nil {
9191
// assemble a signed transaction (it's an Envelope message)
9292
env, err := utils.CreateSignedTx(prop, cf.Signer, proposalResponse)
9393
if err != nil {
94-
return nil, fmt.Errorf("Could not assemble transaction, err %s", err)
94+
return nil, fmt.Errorf("could not assemble transaction, err %s", err)
9595
}
9696

9797
return env, nil

peer/chaincode/package.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func chaincodePackage(cmd *cobra.Command, args []string, cdsFact ccDepSpecFactor
170170

171171
cds, err := cdsFact(spec)
172172
if err != nil {
173-
return fmt.Errorf("Error getting chaincode code %s: %s", chainFuncName, err)
173+
return fmt.Errorf("error getting chaincode code %s: %s", chaincodeName, err)
174174
}
175175

176176
var bytesToWrite []byte
@@ -187,7 +187,7 @@ func chaincodePackage(cmd *cobra.Command, args []string, cdsFact ccDepSpecFactor
187187
fileToWrite := args[0]
188188
err = ioutil.WriteFile(fileToWrite, bytesToWrite, 0700)
189189
if err != nil {
190-
logger.Errorf("Failed writing deployment spec to file [%s]: [%s]", fileToWrite, err)
190+
logger.Errorf("failed writing deployment spec to file [%s]: [%s]", fileToWrite, err)
191191
return err
192192
}
193193

peer/chaincode/upgrade.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,38 @@ func upgrade(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envelope,
6060

6161
cds, err := getChaincodeDeploymentSpec(spec, false)
6262
if err != nil {
63-
return nil, fmt.Errorf("Error getting chaincode code %s: %s", chainFuncName, err)
63+
return nil, fmt.Errorf("error getting chaincode code %s: %s", chaincodeName, err)
6464
}
6565

6666
creator, err := cf.Signer.Serialize()
6767
if err != nil {
68-
return nil, fmt.Errorf("Error serializing identity for %s: %s", cf.Signer.GetIdentifier(), err)
68+
return nil, fmt.Errorf("error serializing identity for %s: %s", cf.Signer.GetIdentifier(), err)
6969
}
7070

7171
prop, _, err := utils.CreateUpgradeProposalFromCDS(channelID, cds, creator, policyMarshalled, []byte(escc), []byte(vscc))
7272
if err != nil {
73-
return nil, fmt.Errorf("Error creating proposal %s: %s", chainFuncName, err)
73+
return nil, fmt.Errorf("error creating proposal %s: %s", chainFuncName, err)
7474
}
7575
logger.Debugf("Get upgrade proposal for chaincode <%v>", spec.ChaincodeId)
7676

7777
var signedProp *pb.SignedProposal
7878
signedProp, err = utils.GetSignedProposal(prop, cf.Signer)
7979
if err != nil {
80-
return nil, fmt.Errorf("Error creating signed proposal %s: %s", chainFuncName, err)
80+
return nil, fmt.Errorf("error creating signed proposal %s: %s", chainFuncName, err)
8181
}
8282

8383
// upgrade is currently only supported for one peer
8484
proposalResponse, err := cf.EndorserClients[0].ProcessProposal(context.Background(), signedProp)
8585
if err != nil {
86-
return nil, fmt.Errorf("Error endorsing %s: %s", chainFuncName, err)
86+
return nil, fmt.Errorf("error endorsing %s: %s", chainFuncName, err)
8787
}
8888
logger.Debugf("endorse upgrade proposal, get response <%v>", proposalResponse.Response)
8989

9090
if proposalResponse != nil {
9191
// assemble a signed transaction (it's an Envelope message)
9292
env, err := utils.CreateSignedTx(prop, cf.Signer, proposalResponse)
9393
if err != nil {
94-
return nil, fmt.Errorf("Could not assemble transaction, err %s", err)
94+
return nil, fmt.Errorf("could not assemble transaction, err %s", err)
9595
}
9696
logger.Debug("Get Signed envelope")
9797
return env, nil

peer/chaincode/upgrade_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestUpgradeCmdEndorseFail(t *testing.T) {
9898
"-v", "anotherversion", "-c", "{\"Function\":\"init\",\"Args\": [\"param\",\"1\"]}"}
9999
cmd.SetArgs(args)
100100

101-
expectErrMsg := fmt.Sprintf("Could not assemble transaction, err Proposal response was not successful, error code %d, msg %s", errCode, errMsg)
101+
expectErrMsg := fmt.Sprintf("could not assemble transaction, err Proposal response was not successful, error code %d, msg %s", errCode, errMsg)
102102
if err := cmd.Execute(); err == nil {
103103
t.Errorf("Run chaincode upgrade cmd error:%v", err)
104104
} else {

0 commit comments

Comments
 (0)