Skip to content

Commit 11ddbbe

Browse files
C0rWinyacovm
authored andcommitted
[FAB-8245] remove extra chars from peer cli output
Do not print extra characters while printing output of block, also this commit takes care of capitalized errors inspection. Change-Id: I9dc55733ea03b74184a3f0112478d9fe31f6c412 Signed-off-by: Artem Barger <bartem@il.ibm.com>
1 parent 8f16f9a commit 11ddbbe

File tree

4 files changed

+47
-46
lines changed

4 files changed

+47
-46
lines changed

examples/e2e_cli/scripts/script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ chaincodeQuery () {
182182
sleep 3
183183
echo "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs"
184184
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt
185-
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}')
185+
test $? -eq 0 && VALUE=$(cat log.txt | egrep '^[0-9]+$')
186186
test "$VALUE" = "$2" && let rc=0
187187
done
188188
echo

peer/chaincode/common.go

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"encoding/json"
1111
"fmt"
1212
"io/ioutil"
13-
"os"
1413
"strings"
1514

1615
"github.com/golang/protobuf/proto"
@@ -34,12 +33,12 @@ import (
3433
func checkSpec(spec *pb.ChaincodeSpec) error {
3534
// Don't allow nil value
3635
if spec == nil {
37-
return errors.New("Expected chaincode specification, nil received")
36+
return errors.New("expected chaincode specification, nil received")
3837
}
3938

4039
platform, err := platforms.Find(spec.Type)
4140
if err != nil {
42-
return fmt.Errorf("Failed to determine platform type: %s", err)
41+
return fmt.Errorf("failed to determine platform type: %s", err)
4342
}
4443

4544
return platform.ValidateSpec(spec)
@@ -56,7 +55,7 @@ func getChaincodeDeploymentSpec(spec *pb.ChaincodeSpec, crtPkg bool) (*pb.Chainc
5655

5756
codePackageBytes, err = container.GetChaincodePackageBytes(spec)
5857
if err != nil {
59-
err = fmt.Errorf("Error getting chaincode package bytes: %s", err)
58+
err = fmt.Errorf("error getting chaincode package bytes: %s", err)
6059
return nil, err
6160
}
6261
}
@@ -74,7 +73,7 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
7473
// Build the spec
7574
input := &pb.ChaincodeInput{}
7675
if err := json.Unmarshal([]byte(chaincodeCtorJSON), &input); err != nil {
77-
return spec, fmt.Errorf("Chaincode argument error: %s", err)
76+
return spec, fmt.Errorf("chaincode argument error: %s", err)
7877
}
7978

8079
chaincodeLang = strings.ToUpper(chaincodeLang)
@@ -83,7 +82,7 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
8382
} else {
8483
logger.Debug("java chaincode disabled")
8584
if pb.ChaincodeSpec_Type_value[chaincodeLang] == int32(pb.ChaincodeSpec_JAVA) {
86-
return nil, fmt.Errorf("Java chaincode is work-in-progress and disabled")
85+
return nil, fmt.Errorf("java chaincode is work-in-progress and disabled")
8786
}
8887
}
8988
spec = &pb.ChaincodeSpec{
@@ -94,7 +93,7 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
9493
return spec, nil
9594
}
9695

97-
func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool, cf *ChaincodeCmdFactory) (err error) {
96+
func chaincodeInvokeOrQuery(cmd *cobra.Command, invoke bool, cf *ChaincodeCmdFactory) (err error) {
9897
spec, err := getChaincodeSpec(cmd)
9998
if err != nil {
10099
return err
@@ -117,43 +116,45 @@ func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool, cf *
117116
logger.Debugf("ESCC invoke result: %v", proposalResp)
118117
pRespPayload, err := putils.GetProposalResponsePayload(proposalResp.Payload)
119118
if err != nil {
120-
return fmt.Errorf("Error while unmarshaling proposal response payload: %s", err)
119+
return fmt.Errorf("error while unmarshaling proposal response payload: %s", err)
121120
}
122121
ca, err := putils.GetChaincodeAction(pRespPayload.Extension)
123122
if err != nil {
124-
return fmt.Errorf("Error while unmarshaling chaincode action: %s", err)
123+
return fmt.Errorf("error while unmarshaling chaincode action: %s", err)
125124
}
126125
logger.Warningf("Endorsement failure during invoke. chaincode result: %v", ca.Response)
127126
} else {
128127
logger.Debugf("ESCC invoke result: %v", proposalResp)
129128
pRespPayload, err := putils.GetProposalResponsePayload(proposalResp.Payload)
130129
if err != nil {
131-
return fmt.Errorf("Error while unmarshaling proposal response payload: %s", err)
130+
return fmt.Errorf("error while unmarshaling proposal response payload: %s", err)
132131
}
133132
ca, err := putils.GetChaincodeAction(pRespPayload.Extension)
134133
if err != nil {
135-
return fmt.Errorf("Error while unmarshaling chaincode action: %s", err)
134+
return fmt.Errorf("error while unmarshaling chaincode action: %s", err)
136135
}
137136
logger.Infof("Chaincode invoke successful. result: %v", ca.Response)
138137
}
139138
} else {
140139
if proposalResp == nil {
141-
return fmt.Errorf("Error query %s by endorsing: %s", chainFuncName, err)
140+
return fmt.Errorf("error query %s by endorsing: %s", chainFuncName, err)
141+
}
142+
143+
if chaincodeQueryRaw && chaincodeQueryHex {
144+
return fmt.Errorf("options --raw (-r) and --hex (-x) are not compatible")
142145
}
143146

144147
if chaincodeQueryRaw {
145-
if chaincodeQueryHex {
146-
return fmt.Errorf("Options --raw (-r) and --hex (-x) are not compatible")
147-
}
148-
fmt.Print("Query Result (Raw): ")
149-
os.Stdout.Write(proposalResp.Response.Payload)
150-
} else {
151-
if chaincodeQueryHex {
152-
fmt.Printf("Query Result: %x\n", proposalResp.Response.Payload)
153-
} else {
154-
fmt.Printf("Query Result: %s\n", string(proposalResp.Response.Payload))
155-
}
148+
fmt.Println(proposalResp.Response.Payload)
149+
return nil
150+
}
151+
152+
if chaincodeQueryHex {
153+
fmt.Printf("%x\n", proposalResp.Response.Payload)
154+
return nil
156155
}
156+
157+
fmt.Println(string(proposalResp.Response.Payload))
157158
}
158159
return nil
159160
}
@@ -214,20 +215,20 @@ func getCollectionConfigFromBytes(cconfBytes []byte) ([]byte, error) {
214215
ccarray = append(ccarray, cc)
215216
}
216217

217-
ccp := &pcommon.CollectionConfigPackage{ccarray}
218+
ccp := &pcommon.CollectionConfigPackage{Config: ccarray}
218219
return proto.Marshal(ccp)
219220
}
220221

221222
func checkChaincodeCmdParams(cmd *cobra.Command) error {
222223
//we need chaincode name for everything, including deploy
223224
if chaincodeName == common.UndefinedParamValue {
224-
return fmt.Errorf("Must supply value for %s name parameter.", chainFuncName)
225+
return fmt.Errorf("must supply value for %s name parameter", chainFuncName)
225226
}
226227

227228
if cmd.Name() == instantiateCmdName || cmd.Name() == installCmdName ||
228229
cmd.Name() == upgradeCmdName || cmd.Name() == packageCmdName {
229230
if chaincodeVersion == common.UndefinedParamValue {
230-
return fmt.Errorf("Chaincode version is not provided for %s", cmd.Name())
231+
return fmt.Errorf("chaincode version is not provided for %s", cmd.Name())
231232
}
232233
}
233234

@@ -248,7 +249,7 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error {
248249
if policy != common.UndefinedParamValue {
249250
p, err := cauthdsl.FromString(policy)
250251
if err != nil {
251-
return fmt.Errorf("Invalid policy %s", policy)
252+
return fmt.Errorf("invalid policy %s", policy)
252253
}
253254
policyMarshalled = putils.MarshalOrPanic(p)
254255
}
@@ -270,7 +271,7 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error {
270271
var f interface{}
271272
err := json.Unmarshal([]byte(chaincodeCtorJSON), &f)
272273
if err != nil {
273-
return fmt.Errorf("Chaincode argument error: %s", err)
274+
return fmt.Errorf("chaincode argument error: %s", err)
274275
}
275276
m := f.(map[string]interface{})
276277
sm := make(map[string]interface{})
@@ -305,24 +306,24 @@ func InitCmdFactory(isEndorserRequired, isOrdererRequired bool) (*ChaincodeCmdFa
305306
if isEndorserRequired {
306307
endorserClient, err = common.GetEndorserClientFnc()
307308
if err != nil {
308-
return nil, fmt.Errorf("Error getting endorser client %s: %s", chainFuncName, err)
309+
return nil, fmt.Errorf("error getting endorser client %s: %s", chainFuncName, err)
309310
}
310311
}
311312

312313
signer, err := common.GetDefaultSignerFnc()
313314
if err != nil {
314-
return nil, fmt.Errorf("Error getting default signer: %s", err)
315+
return nil, fmt.Errorf("error getting default signer: %s", err)
315316
}
316317

317318
var broadcastClient common.BroadcastClient
318319
if isOrdererRequired {
319320
if len(common.OrderingEndpoint) == 0 {
320321
orderingEndpoints, err := common.GetOrdererEndpointOfChainFnc(channelID, signer, endorserClient)
321322
if err != nil {
322-
return nil, fmt.Errorf("Error getting (%s) orderer endpoint: %s", channelID, err)
323+
return nil, fmt.Errorf("error getting (%s) orderer endpoint: %s", channelID, err)
323324
}
324325
if len(orderingEndpoints) == 0 {
325-
return nil, fmt.Errorf("Error no orderer endpoint got for %s", channelID)
326+
return nil, fmt.Errorf("error no orderer endpoint got for %s", channelID)
326327
}
327328
logger.Infof("Get chain(%s) orderer endpoint: %s", channelID, orderingEndpoints[0])
328329
// override viper env
@@ -332,7 +333,7 @@ func InitCmdFactory(isEndorserRequired, isOrdererRequired bool) (*ChaincodeCmdFa
332333
broadcastClient, err = common.GetBroadcastClientFnc()
333334

334335
if err != nil {
335-
return nil, fmt.Errorf("Error getting broadcast client: %s", err)
336+
return nil, fmt.Errorf("error getting broadcast client: %s", err)
336337
}
337338
}
338339
return &ChaincodeCmdFactory{
@@ -367,7 +368,7 @@ func ChaincodeInvokeOrQuery(
367368

368369
creator, err := signer.Serialize()
369370
if err != nil {
370-
return nil, fmt.Errorf("Error serializing identity for %s: %s", signer.GetIdentifier(), err)
371+
return nil, fmt.Errorf("error serializing identity for %s: %s", signer.GetIdentifier(), err)
371372
}
372373

373374
funcName := "invoke"
@@ -379,7 +380,7 @@ func ChaincodeInvokeOrQuery(
379380
var tMap map[string][]byte
380381
if transient != "" {
381382
if err := json.Unmarshal([]byte(transient), &tMap); err != nil {
382-
return nil, fmt.Errorf("Error parsing transient string: %s", err)
383+
return nil, fmt.Errorf("error parsing transient string: %s", err)
383384
}
384385
}
385386

@@ -392,13 +393,13 @@ func ChaincodeInvokeOrQuery(
392393
var signedProp *pb.SignedProposal
393394
signedProp, err = putils.GetSignedProposal(prop, signer)
394395
if err != nil {
395-
return nil, fmt.Errorf("Error creating signed proposal %s: %s", funcName, err)
396+
return nil, fmt.Errorf("error creating signed proposal %s: %s", funcName, err)
396397
}
397398

398399
var proposalResp *pb.ProposalResponse
399400
proposalResp, err = endorserClient.ProcessProposal(context.Background(), signedProp)
400401
if err != nil {
401-
return nil, fmt.Errorf("Error endorsing %s: %s", funcName, err)
402+
return nil, fmt.Errorf("error endorsing %s: %s", funcName, err)
402403
}
403404

404405
if invoke {
@@ -409,12 +410,12 @@ func ChaincodeInvokeOrQuery(
409410
// assemble a signed transaction (it's an Envelope message)
410411
env, err := putils.CreateSignedTx(prop, signer, proposalResp)
411412
if err != nil {
412-
return proposalResp, fmt.Errorf("Could not assemble transaction, err %s", err)
413+
return proposalResp, fmt.Errorf("could not assemble transaction, err %s", err)
413414
}
414415

415416
// send the envelope for ordering
416417
if err = bc.Send(env); err != nil {
417-
return proposalResp, fmt.Errorf("Error sending transaction %s: %s", funcName, err)
418+
return proposalResp, fmt.Errorf("error sending transaction %s: %s", funcName, err)
418419
}
419420
}
420421
}

peer/chaincode/invoke.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func invokeCmd(cf *ChaincodeCmdFactory) *cobra.Command {
3333
Long: fmt.Sprintf("Invoke the specified %s. It will try to commit the endorsed transaction to the network.", chainFuncName),
3434
ValidArgs: []string{"1"},
3535
RunE: func(cmd *cobra.Command, args []string) error {
36-
return chaincodeInvoke(cmd, args, cf)
36+
return chaincodeInvoke(cmd, cf)
3737
},
3838
}
3939
flagList := []string{
@@ -46,7 +46,7 @@ func invokeCmd(cf *ChaincodeCmdFactory) *cobra.Command {
4646
return chaincodeInvokeCmd
4747
}
4848

49-
func chaincodeInvoke(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
49+
func chaincodeInvoke(cmd *cobra.Command, cf *ChaincodeCmdFactory) error {
5050
if channelID == "" {
5151
return errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag")
5252
}
@@ -59,5 +59,5 @@ func chaincodeInvoke(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory)
5959
}
6060
defer cf.BroadcastClient.Close()
6161

62-
return chaincodeInvokeOrQuery(cmd, args, true, cf)
62+
return chaincodeInvokeOrQuery(cmd, true, cf)
6363
}

peer/chaincode/query.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func queryCmd(cf *ChaincodeCmdFactory) *cobra.Command {
3333
Long: fmt.Sprintf("Get endorsed result of %s function call and print it. It won't generate transaction.", chainFuncName),
3434
ValidArgs: []string{"1"},
3535
RunE: func(cmd *cobra.Command, args []string) error {
36-
return chaincodeQuery(cmd, args, cf)
36+
return chaincodeQuery(cmd, cf)
3737
},
3838
}
3939
flagList := []string{
@@ -52,7 +52,7 @@ func queryCmd(cf *ChaincodeCmdFactory) *cobra.Command {
5252
return chaincodeQueryCmd
5353
}
5454

55-
func chaincodeQuery(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
55+
func chaincodeQuery(cmd *cobra.Command, cf *ChaincodeCmdFactory) error {
5656
if channelID == "" {
5757
return errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag")
5858
}
@@ -64,5 +64,5 @@ func chaincodeQuery(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory)
6464
}
6565
}
6666

67-
return chaincodeInvokeOrQuery(cmd, args, false, cf)
67+
return chaincodeInvokeOrQuery(cmd, false, cf)
6868
}

0 commit comments

Comments
 (0)