Skip to content

Commit d0e6fe8

Browse files
committed
[FAB-1535]Cleanup several pycharm warnings
https://jira.hyperledger.org/browse/FAB-1535 Some warings are reported by pycharm IDE, this commit fixs warnings. Specific warnings list in JIRA ticket. Change-Id: I122ea6627627893e74227580468309e31a5d47e3 Signed-off-by: grapebaba <[email protected]>
1 parent b3c0fba commit d0e6fe8

File tree

8 files changed

+32
-28
lines changed

8 files changed

+32
-28
lines changed

core/chaincode/platforms/car/hash.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"fmt"
2222
"io/ioutil"
2323

24+
"errors"
25+
2426
"github.com/golang/protobuf/proto"
2527
"github.com/hyperledger/fabric/core/util"
2628
pb "github.com/hyperledger/fabric/protos/peer"
@@ -36,7 +38,7 @@ func generateHashcode(spec *pb.ChaincodeSpec, path string) (string, error) {
3638

3739
ctor := spec.CtorMsg
3840
if ctor == nil || len(ctor.Args) == 0 {
39-
return "", fmt.Errorf("Cannot generate hashcode from empty ctor")
41+
return "", errors.New("Cannot generate hashcode from empty ctor")
4042
}
4143
ctorbytes, err := proto.Marshal(ctor)
4244
if err != nil {

core/chaincode/platforms/car/test/car_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,19 @@ func TestCar_BuildImage(t *testing.T) {
3535
vm, err := container.NewVM()
3636

3737
if err != nil {
38-
t.Fail()
39-
t.Logf("Error getting VM: %s", err)
38+
t.Errorf("Error getting VM: %s", err)
4039
return
4140
}
4241
// Build the spec
4342
cwd, err := os.Getwd()
4443
if err != nil {
45-
t.Fail()
46-
t.Logf("Error getting CWD: %s", err)
44+
t.Errorf("Error getting CWD: %s", err)
4745
return
4846
}
4947

5048
chaincodePath := cwd + "/org.hyperledger.chaincode.example02-0.1-SNAPSHOT.car"
5149
spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_CAR, ChaincodeID: &pb.ChaincodeID{Name: "cartest", Path: chaincodePath}, CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}}
5250
if _, err := vm.BuildChaincodeContainer(spec); err != nil {
53-
t.Fail()
54-
t.Log(err)
51+
t.Error(err)
5552
}
5653
}

core/chaincode/platforms/golang/hash.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func getCodeFromHTTP(path string) (codegopath string, err error) {
5858
}
5959
}
6060
if origgopath == "" {
61-
err = fmt.Errorf("GOPATH not defined")
61+
err = errors.New("GOPATH not defined")
6262
return
6363
}
6464
// Only take the first element of GOPATH
@@ -126,7 +126,7 @@ func getCodeFromFS(path string) (codegopath string, err error) {
126126
logger.Debugf("getCodeFromFS %s", path)
127127
gopath := os.Getenv("GOPATH")
128128
if gopath == "" {
129-
err = fmt.Errorf("GOPATH not defined")
129+
err = errors.New("GOPATH not defined")
130130
return
131131
}
132132
// Only take the first element of GOPATH
@@ -143,17 +143,17 @@ func getCodeFromFS(path string) (codegopath string, err error) {
143143
//with the same (name, ctor, args)
144144
func collectChaincodeFiles(spec *pb.ChaincodeSpec, tw *tar.Writer) (string, error) {
145145
if spec == nil {
146-
return "", fmt.Errorf("Cannot collect files from nil spec")
146+
return "", errors.New("Cannot collect files from nil spec")
147147
}
148148

149149
chaincodeID := spec.ChaincodeID
150150
if chaincodeID == nil || chaincodeID.Path == "" {
151-
return "", fmt.Errorf("Cannot collect files from empty chaincode path")
151+
return "", errors.New("Cannot collect files from empty chaincode path")
152152
}
153153

154154
ctor := spec.CtorMsg
155155
if ctor == nil || len(ctor.Args) == 0 {
156-
return "", fmt.Errorf("Cannot collect files from empty ctor")
156+
return "", errors.New("Cannot collect files from empty ctor")
157157
}
158158

159159
//code root will point to the directory where the code exists

core/chaincode/platforms/golang/package.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424

2525
"github.com/spf13/viper"
2626

27+
"errors"
28+
2729
cutil "github.com/hyperledger/fabric/core/container/util"
2830
pb "github.com/hyperledger/fabric/protos/peer"
2931
)
@@ -42,7 +44,7 @@ func writeChaincodePackage(spec *pb.ChaincodeSpec, tw *tar.Writer) error {
4244
}
4345

4446
if urlLocation == "" {
45-
return fmt.Errorf("empty url location")
47+
return errors.New("ChaincodeSpec's path/URL cannot be empty")
4648
}
4749

4850
if strings.LastIndex(urlLocation, "/") == len(urlLocation)-1 {

core/chaincode/platforms/golang/platform.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ func pathExists(path string) (bool, error) {
4444

4545
// ValidateSpec validates Go chaincodes
4646
func (goPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
47-
url, err := url.Parse(spec.ChaincodeID.Path)
48-
if err != nil || url == nil {
47+
path, err := url.Parse(spec.ChaincodeID.Path)
48+
if err != nil || path == nil {
4949
return fmt.Errorf("invalid path: %s", err)
5050
}
5151

5252
//we have no real good way of checking existence of remote urls except by downloading and testin
5353
//which we do later anyway. But we *can* - and *should* - test for existence of local paths.
5454
//Treat empty scheme as a local filesystem path
55-
if url.Scheme == "" {
55+
if path.Scheme == "" {
5656
gopath := os.Getenv("GOPATH")
5757
// Only take the first element of GOPATH
5858
gopath = filepath.SplitList(gopath)[0]

core/chaincode/platforms/java/hash.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"os/exec"
2727
"strings"
2828

29+
"errors"
30+
2931
"github.com/golang/protobuf/proto"
3032
ccutil "github.com/hyperledger/fabric/core/chaincode/platforms/util"
3133
"github.com/hyperledger/fabric/core/util"
@@ -34,22 +36,21 @@ import (
3436

3537
func getCodeFromHTTP(path string) (codegopath string, err error) {
3638

37-
var tmp string
38-
tmp, err = ioutil.TempDir("", "javachaincode")
39+
codegopath, err = ioutil.TempDir("", "javachaincode")
3940

4041
if err != nil {
4142
return "", fmt.Errorf("Error creating temporary file: %s", err)
4243
}
4344
var out bytes.Buffer
4445

45-
cmd := exec.Command("git", "clone", path, tmp)
46+
cmd := exec.Command("git", "clone", path, codegopath)
4647
cmd.Stderr = &out
4748
cmderr := cmd.Run()
4849
if cmderr != nil {
4950
return "", fmt.Errorf("Error cloning git repository %s", cmderr)
5051
}
5152

52-
return tmp, nil
53+
return codegopath, nil
5354

5455
}
5556

@@ -61,17 +62,17 @@ func getCodeFromHTTP(path string) (codegopath string, err error) {
6162
//with the same (name, ctor, args)
6263
func collectChaincodeFiles(spec *pb.ChaincodeSpec, tw *tar.Writer) (string, error) {
6364
if spec == nil {
64-
return "", fmt.Errorf("Cannot collect chaincode files from nil spec")
65+
return "", errors.New("Cannot collect chaincode files from nil spec")
6566
}
6667

6768
chaincodeID := spec.ChaincodeID
6869
if chaincodeID == nil || chaincodeID.Path == "" {
69-
return "", fmt.Errorf("Cannot collect chaincode files from empty chaincode path")
70+
return "", errors.New("Cannot collect chaincode files from empty chaincode path")
7071
}
7172

7273
ctor := spec.CtorMsg
7374
if ctor == nil || len(ctor.Args) == 0 {
74-
return "", fmt.Errorf("Cannot collect chaincode files from empty ctor")
75+
return "", errors.New("Cannot collect chaincode files from empty ctor")
7576
}
7677

7778
codepath := chaincodeID.Path

core/chaincode/platforms/java/package.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525

2626
"os"
2727

28+
"errors"
29+
2830
cutil "github.com/hyperledger/fabric/core/container/util"
2931
pb "github.com/hyperledger/fabric/protos/peer"
3032
"github.com/spf13/viper"
@@ -35,7 +37,7 @@ var buildCmd = map[string]string{
3537
"pom.xml": "mvn -f pom.xml clean && mvn -f pom.xml package",
3638
}
3739

38-
//return the type of build gradle/maven based on the file
40+
//getBuildCmd returns the type of build gradle/maven based on the file
3941
//found in java chaincode project root
4042
//build.gradle - gradle - returns the first found build type
4143
//pom.xml - maven
@@ -51,7 +53,7 @@ func getBuildCmd(packagePath string) (string, error) {
5153
}
5254
}
5355
}
54-
return "", fmt.Errorf("Build file not found")
56+
return "", errors.New("Build file not found")
5557
}
5658
}
5759

@@ -77,7 +79,7 @@ func writeChaincodePackage(spec *pb.ChaincodeSpec, tw *tar.Writer) error {
7779
}
7880

7981
if urlLocation == "" {
80-
return fmt.Errorf("empty url location")
82+
return errors.New("ChaincodeSpec's path/URL cannot be empty")
8183
}
8284

8385
if strings.LastIndex(urlLocation, "/") == len(urlLocation)-1 {

core/chaincode/platforms/java/platform.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type Platform struct {
3131

3232
//ValidateSpec validates the java chaincode specs
3333
func (javaPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
34-
url, err := url.Parse(spec.ChaincodeID.Path)
35-
if err != nil || url == nil {
34+
path, err := url.Parse(spec.ChaincodeID.Path)
35+
if err != nil || path == nil {
3636
return fmt.Errorf("invalid path: %s", err)
3737
}
3838

0 commit comments

Comments
 (0)