Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 7a42841

Browse files
committed
[FAB-11048] Fix metalinter issues
This change updates the gas linter to the latest and overrides the linter configuration. The scripts also now account for changed linter configuration as a change. Third party directories are now explicitly ignored. Linter issues are resolved. Change-Id: I66c39ca04ad636ec5a5c71d7fba0c9c025f00f85 Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent 139bfdf commit 7a42841

File tree

18 files changed

+124
-57
lines changed

18 files changed

+124
-57
lines changed

gometalinter.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"Deadline": "5m",
33
"Exclude": [
44
".*seekInfo can be .*proto.Message.*",
5-
"test/integration/msp/check_cert_attributes.go",
6-
"test/integration/msp/check_cert_ser_attributes_prev.go",
7-
"test/fixtures/testdata/..."
5+
"^test/integration/msp/check_cert_attributes.go",
6+
"^test/integration/msp/check_cert_ser_attributes_prev.go",
7+
"^internal/github.com/",
8+
"^third_party/"
89
],
910
"EnableGC": true,
1011
"WarnUnmatchedDirective": true,
12+
"Vendor": true,
1113
"Enable": [
1214
"deadcode",
1315
"gocyclo",
@@ -30,6 +32,16 @@
3032
"gas",
3133
"structcheck"
3234
],
35+
"Linters": {
36+
"gas": {
37+
"Command": "gas -fmt=csv",
38+
"Pattern": "^(?P<path>.*?\\.go),(?P<line>\\d+)(-\\d+)?,(?P<message>[^,]+,[^,]+,[^,]+)",
39+
"InstallFrom": "github.com/GoASTScanner/gas",
40+
"PartitionStrategy": "packages",
41+
"defaultEnabled": true,
42+
"IsFast": true
43+
}
44+
},
3345
"Cyclo": 10,
3446
"Aggregate": true
3547
}

pkg/client/channel/chclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (cc *Client) InvokeHandler(handler invoke.Handler, request Request, options
179179

180180
complete := make(chan bool, 1)
181181
go func() {
182-
_, _ = invoker.Invoke(
182+
_, _ = invoker.Invoke( // nolint: gas
183183
func() (interface{}, error) {
184184
handler.Handle(requestContext, clientContext)
185185
return nil, requestContext.Error

pkg/client/common/selection/fabricselection/fabricselection.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ func (s *Service) newChannelResponseRef(chaincodes []*fab.ChaincodeCall, refresh
162162
return lazyref.New(
163163
func() (interface{}, error) {
164164
if logging.IsEnabledFor(moduleName, logging.DEBUG) {
165-
key, _ := json.Marshal(chaincodes)
165+
key, err := json.Marshal(chaincodes)
166+
if err != nil {
167+
panic(fmt.Sprintf("marshal of chaincodes failed: %s", err))
168+
}
169+
166170
logger.Debugf("Refreshing endorsers for chaincodes [%s] in channel [%s] from discovery service...", key, s.channelID)
167171
}
168172
return s.queryEndorsers(chaincodes)

pkg/client/resmgmt/resmgmt.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func (rc *Client) InstallCC(req InstallCCRequest, options ...RequestOption) ([]I
405405
reqCtx, cancel := contextImpl.NewRequest(rc.ctx, contextImpl.WithTimeoutType(fab.ResMgmt), contextImpl.WithParent(parentReqCtx))
406406
defer cancel()
407407

408-
responses = rc.sendIntallCCRequest(req, reqCtx, newTargets, responses)
408+
responses, err = rc.sendInstallCCRequest(req, reqCtx, newTargets, responses)
409409

410410
if err != nil {
411411
installErrs, ok := err.(multi.Errors)
@@ -419,16 +419,20 @@ func (rc *Client) InstallCC(req InstallCCRequest, options ...RequestOption) ([]I
419419
return responses, errs.ToError()
420420
}
421421

422-
func (rc *Client) sendIntallCCRequest(req InstallCCRequest, reqCtx reqContext.Context, newTargets []fab.Peer, responses []InstallCCResponse) []InstallCCResponse {
422+
func (rc *Client) sendInstallCCRequest(req InstallCCRequest, reqCtx reqContext.Context, newTargets []fab.Peer, responses []InstallCCResponse) ([]InstallCCResponse, error) {
423423
icr := resource.InstallChaincodeRequest{Name: req.Name, Path: req.Path, Version: req.Version, Package: req.Package}
424-
transactionProposalResponse, _, _ := resource.InstallChaincode(reqCtx, icr, peer.PeersToTxnProcessors(newTargets))
424+
transactionProposalResponse, _, err := resource.InstallChaincode(reqCtx, icr, peer.PeersToTxnProcessors(newTargets))
425+
if err != nil {
426+
return nil, errors.WithMessage(err, "installing chaincode failed")
427+
}
428+
425429
for _, v := range transactionProposalResponse {
426430
logger.Debugf("Install chaincode '%s' endorser '%s' returned ProposalResponse status:%v", req.Name, v.Endorser, v.Status)
427431

428432
response := InstallCCResponse{Target: v.Endorser, Status: v.Status}
429433
responses = append(responses, response)
430434
}
431-
return responses
435+
return responses, nil
432436
}
433437

434438
func (rc *Client) adjustTargets(targets []fab.Peer, req InstallCCRequest, retry retry.Opts, parentReqCtx reqContext.Context) ([]InstallCCResponse, []fab.Peer, multi.Errors) {

pkg/fab/keyvaluestore/filekeyvaluestore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (fkvs *FileKeyValueStore) Load(key interface{}) (interface{}, error) {
116116
if _, err1 := os.Stat(file); os.IsNotExist(err1) {
117117
return nil, core.ErrKeyValueNotFound
118118
}
119-
bytes, err := ioutil.ReadFile(file)
119+
bytes, err := ioutil.ReadFile(file) // nolint: gas
120120
if err != nil {
121121
return nil, err
122122
}

pkg/fab/peer/peerendorser.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,15 @@ func (p *peerEndorser) ProcessTransactionProposal(ctx reqContext.Context, reques
108108
return &tpr, errors.Wrapf(err, "Transaction processing for endorser [%s]", p.target)
109109
}
110110

111+
chaincodeStatus, err := getChaincodeResponseStatus(proposalResponse)
112+
if err != nil {
113+
return nil, errors.WithMessage(err, "chaincode response status parsing failed")
114+
}
115+
111116
tpr := fab.TransactionProposalResponse{
112117
ProposalResponse: proposalResponse,
113118
Endorser: p.target,
114-
ChaincodeStatus: getChaincodeResponseStatus(proposalResponse),
119+
ChaincodeStatus: chaincodeStatus,
115120
Status: proposalResponse.GetResponse().Status,
116121
}
117122
return &tpr, nil
@@ -287,13 +292,21 @@ func extractChaincodeNameNotFoundError(grpcstat *grpcstatus.Status) (int32, stri
287292
}
288293

289294
// getChaincodeResponseStatus gets the actual response status from response.Payload.extension.Response.status, as fabric always returns actual 200
290-
func getChaincodeResponseStatus(response *pb.ProposalResponse) int32 {
295+
func getChaincodeResponseStatus(response *pb.ProposalResponse) (int32, error) {
291296
if response.Payload != nil {
292-
payload, _ := protos_utils.GetProposalResponsePayload(response.Payload)
293-
extension, _ := protos_utils.GetChaincodeAction(payload.Extension)
297+
payload, err := protos_utils.GetProposalResponsePayload(response.Payload)
298+
if err != nil {
299+
return 0, errors.Wrap(err, "unmarshal of proposal response payload failed")
300+
}
301+
302+
extension, err := protos_utils.GetChaincodeAction(payload.Extension)
303+
if err != nil {
304+
return 0, errors.Wrap(err, "unmarshal of chaincode action failed")
305+
}
306+
294307
if extension != nil && extension.Response != nil {
295-
return extension.Response.Status
308+
return extension.Response.Status, nil
296309
}
297310
}
298-
return response.Response.Status
311+
return response.Response.Status, nil
299312
}

pkg/fab/resource/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func InstallChaincode(reqCtx reqContext.Context, req InstallChaincodeRequest, ta
361361
return nil, fab.EmptyTransactionID, err
362362
}
363363

364-
return resp.([]*fab.TransactionProposalResponse), prop.TxnID, err
364+
return resp.([]*fab.TransactionProposalResponse), prop.TxnID, nil
365365
}
366366

367367
func queryChaincodeWithTarget(reqCtx reqContext.Context, request fab.ChaincodeInvokeRequest, target fab.ProposalProcessor, opts options) ([]byte, error) {

pkg/util/concurrent/futurevalue/futurevalue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func (f *Value) MustGet() interface{} {
8080

8181
// IsSet returns true if the value has been set, otherwise false is returned
8282
func (f *Value) IsSet() bool {
83-
isSet, _, _ := f.get() //nolint
84-
return isSet
83+
p := atomic.LoadPointer(&f.ref)
84+
return p != nil
8585
}
8686

8787
func (f *Value) get() (bool, interface{}, error) {

pkg/util/pathvar/subst.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ func Subst(path string) string {
3636
splits := strings.Split(path, sepPrefix)
3737

3838
var buffer bytes.Buffer
39-
buffer.WriteString(splits[0]) // first split precedes the first sepPrefix so should always be written
39+
40+
// first split precedes the first sepPrefix so should always be written
41+
buffer.WriteString(splits[0]) // nolint: gas
4042

4143
for _, s := range splits[1:] {
4244
subst, rest := substVar(s, sepPrefix, sepSuffix)
43-
buffer.WriteString(subst)
44-
buffer.WriteString(rest)
45+
buffer.WriteString(subst) // nolint: gas
46+
buffer.WriteString(rest) // nolint: gas
4547
}
4648

4749
return buffer.String()

pkg/util/test/test.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,44 @@ import (
1313
"testing"
1414
)
1515

16-
// nolint
1716
// Logf writes to stdout and flushes. Applicable for when t.Logf can't be used.
1817
func Logf(template string, args ...interface{}) {
1918
f := bufio.NewWriter(os.Stdout)
20-
defer f.Flush()
2119

22-
f.Write([]byte(fmt.Sprintf(template, args...)))
23-
f.Write([]byte(fmt.Sprintln()))
20+
_, err := f.WriteString(fmt.Sprintf(template, args...))
21+
if err != nil {
22+
panic(fmt.Sprintf("writing to output failed: %s", err))
23+
}
24+
25+
err = f.WriteByte('\n')
26+
if err != nil {
27+
panic(fmt.Sprintf("writing to output failed: %s", err))
28+
}
29+
30+
err = f.Flush()
31+
if err != nil {
32+
panic(fmt.Sprintf("writing to output failed: %s", err))
33+
}
2434
}
2535

26-
// nolint
27-
// Failf - as t.Fatalf() is not goroutine safe, this function behaves like t.Fatalf().
36+
// Failf - as t.Fatalf is not goroutine safe, this function behaves like t.Fatalf.
2837
func Failf(t *testing.T, template string, args ...interface{}) {
2938
f := bufio.NewWriter(os.Stdout)
30-
defer f.Flush()
3139

32-
f.Write([]byte(fmt.Sprintf(template, args...)))
33-
f.Write([]byte(fmt.Sprintln()))
40+
_, err := f.WriteString(fmt.Sprintf(template, args...))
41+
if err != nil {
42+
panic(fmt.Sprintf("writing to output failed: %s", err))
43+
}
44+
45+
err = f.WriteByte('\n')
46+
if err != nil {
47+
panic(fmt.Sprintf("writing to output failed: %s", err))
48+
}
49+
50+
err = f.Flush()
51+
if err != nil {
52+
panic(fmt.Sprintf("writing to output failed: %s", err))
53+
}
54+
3455
t.Fail()
3556
}

0 commit comments

Comments
 (0)