diff --git a/core/chaincode/platforms/car/hash.go b/core/chaincode/platforms/car/hash.go index 98c82b5ebee..a52ab827306 100644 --- a/core/chaincode/platforms/car/hash.go +++ b/core/chaincode/platforms/car/hash.go @@ -21,6 +21,8 @@ import ( "fmt" "io/ioutil" + "errors" + "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric/core/util" pb "github.com/hyperledger/fabric/protos/peer" @@ -36,7 +38,7 @@ func generateHashcode(spec *pb.ChaincodeSpec, path string) (string, error) { ctor := spec.CtorMsg if ctor == nil || len(ctor.Args) == 0 { - return "", fmt.Errorf("Cannot generate hashcode from empty ctor") + return "", errors.New("Cannot generate hashcode from empty ctor") } ctorbytes, err := proto.Marshal(ctor) if err != nil { diff --git a/core/chaincode/platforms/car/test/car_test.go b/core/chaincode/platforms/car/test/car_test.go index 616b0906bf4..d7c81cf8ae1 100644 --- a/core/chaincode/platforms/car/test/car_test.go +++ b/core/chaincode/platforms/car/test/car_test.go @@ -35,22 +35,19 @@ func TestCar_BuildImage(t *testing.T) { vm, err := container.NewVM() if err != nil { - t.Fail() - t.Logf("Error getting VM: %s", err) + t.Errorf("Error getting VM: %s", err) return } // Build the spec cwd, err := os.Getwd() if err != nil { - t.Fail() - t.Logf("Error getting CWD: %s", err) + t.Errorf("Error getting CWD: %s", err) return } chaincodePath := cwd + "/org.hyperledger.chaincode.example02-0.1-SNAPSHOT.car" spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_CAR, ChaincodeID: &pb.ChaincodeID{Name: "cartest", Path: chaincodePath}, CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}} if _, err := vm.BuildChaincodeContainer(spec); err != nil { - t.Fail() - t.Log(err) + t.Error(err) } } diff --git a/core/chaincode/platforms/golang/hash.go b/core/chaincode/platforms/golang/hash.go index f00406fa959..c888a7281d2 100755 --- a/core/chaincode/platforms/golang/hash.go +++ b/core/chaincode/platforms/golang/hash.go @@ -58,7 +58,7 @@ func getCodeFromHTTP(path string) (codegopath string, err error) { } } if origgopath == "" { - err = fmt.Errorf("GOPATH not defined") + err = errors.New("GOPATH not defined") return } // Only take the first element of GOPATH @@ -126,7 +126,7 @@ func getCodeFromFS(path string) (codegopath string, err error) { logger.Debugf("getCodeFromFS %s", path) gopath := os.Getenv("GOPATH") if gopath == "" { - err = fmt.Errorf("GOPATH not defined") + err = errors.New("GOPATH not defined") return } // Only take the first element of GOPATH @@ -143,17 +143,17 @@ func getCodeFromFS(path string) (codegopath string, err error) { //with the same (name, ctor, args) func collectChaincodeFiles(spec *pb.ChaincodeSpec, tw *tar.Writer) (string, error) { if spec == nil { - return "", fmt.Errorf("Cannot collect files from nil spec") + return "", errors.New("Cannot collect files from nil spec") } chaincodeID := spec.ChaincodeID if chaincodeID == nil || chaincodeID.Path == "" { - return "", fmt.Errorf("Cannot collect files from empty chaincode path") + return "", errors.New("Cannot collect files from empty chaincode path") } ctor := spec.CtorMsg if ctor == nil || len(ctor.Args) == 0 { - return "", fmt.Errorf("Cannot collect files from empty ctor") + return "", errors.New("Cannot collect files from empty ctor") } //code root will point to the directory where the code exists diff --git a/core/chaincode/platforms/golang/package.go b/core/chaincode/platforms/golang/package.go index ac482460fa2..d461c8ea27a 100644 --- a/core/chaincode/platforms/golang/package.go +++ b/core/chaincode/platforms/golang/package.go @@ -24,6 +24,8 @@ import ( "github.com/spf13/viper" + "errors" + cutil "github.com/hyperledger/fabric/core/container/util" pb "github.com/hyperledger/fabric/protos/peer" ) @@ -42,7 +44,7 @@ func writeChaincodePackage(spec *pb.ChaincodeSpec, tw *tar.Writer) error { } if urlLocation == "" { - return fmt.Errorf("empty url location") + return errors.New("ChaincodeSpec's path/URL cannot be empty") } if strings.LastIndex(urlLocation, "/") == len(urlLocation)-1 { diff --git a/core/chaincode/platforms/golang/platform.go b/core/chaincode/platforms/golang/platform.go index 31f19185e96..46ff49d4b64 100644 --- a/core/chaincode/platforms/golang/platform.go +++ b/core/chaincode/platforms/golang/platform.go @@ -44,15 +44,15 @@ func pathExists(path string) (bool, error) { // ValidateSpec validates Go chaincodes func (goPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error { - url, err := url.Parse(spec.ChaincodeID.Path) - if err != nil || url == nil { + path, err := url.Parse(spec.ChaincodeID.Path) + if err != nil || path == nil { return fmt.Errorf("invalid path: %s", err) } //we have no real good way of checking existence of remote urls except by downloading and testin //which we do later anyway. But we *can* - and *should* - test for existence of local paths. //Treat empty scheme as a local filesystem path - if url.Scheme == "" { + if path.Scheme == "" { gopath := os.Getenv("GOPATH") // Only take the first element of GOPATH gopath = filepath.SplitList(gopath)[0] diff --git a/core/chaincode/platforms/java/hash.go b/core/chaincode/platforms/java/hash.go index 40d1638dfe0..675f513c6e1 100644 --- a/core/chaincode/platforms/java/hash.go +++ b/core/chaincode/platforms/java/hash.go @@ -26,6 +26,8 @@ import ( "os/exec" "strings" + "errors" + "github.com/golang/protobuf/proto" ccutil "github.com/hyperledger/fabric/core/chaincode/platforms/util" "github.com/hyperledger/fabric/core/util" @@ -34,22 +36,21 @@ import ( func getCodeFromHTTP(path string) (codegopath string, err error) { - var tmp string - tmp, err = ioutil.TempDir("", "javachaincode") + codegopath, err = ioutil.TempDir("", "javachaincode") if err != nil { return "", fmt.Errorf("Error creating temporary file: %s", err) } var out bytes.Buffer - cmd := exec.Command("git", "clone", path, tmp) + cmd := exec.Command("git", "clone", path, codegopath) cmd.Stderr = &out cmderr := cmd.Run() if cmderr != nil { return "", fmt.Errorf("Error cloning git repository %s", cmderr) } - return tmp, nil + return codegopath, nil } @@ -61,17 +62,17 @@ func getCodeFromHTTP(path string) (codegopath string, err error) { //with the same (name, ctor, args) func collectChaincodeFiles(spec *pb.ChaincodeSpec, tw *tar.Writer) (string, error) { if spec == nil { - return "", fmt.Errorf("Cannot collect chaincode files from nil spec") + return "", errors.New("Cannot collect chaincode files from nil spec") } chaincodeID := spec.ChaincodeID if chaincodeID == nil || chaincodeID.Path == "" { - return "", fmt.Errorf("Cannot collect chaincode files from empty chaincode path") + return "", errors.New("Cannot collect chaincode files from empty chaincode path") } ctor := spec.CtorMsg if ctor == nil || len(ctor.Args) == 0 { - return "", fmt.Errorf("Cannot collect chaincode files from empty ctor") + return "", errors.New("Cannot collect chaincode files from empty ctor") } codepath := chaincodeID.Path diff --git a/core/chaincode/platforms/java/package.go b/core/chaincode/platforms/java/package.go index 8c0800b1570..5413ae5f4a2 100644 --- a/core/chaincode/platforms/java/package.go +++ b/core/chaincode/platforms/java/package.go @@ -25,6 +25,8 @@ import ( "os" + "errors" + cutil "github.com/hyperledger/fabric/core/container/util" pb "github.com/hyperledger/fabric/protos/peer" "github.com/spf13/viper" @@ -35,7 +37,7 @@ var buildCmd = map[string]string{ "pom.xml": "mvn -f pom.xml clean && mvn -f pom.xml package", } -//return the type of build gradle/maven based on the file +//getBuildCmd returns the type of build gradle/maven based on the file //found in java chaincode project root //build.gradle - gradle - returns the first found build type //pom.xml - maven @@ -51,7 +53,7 @@ func getBuildCmd(packagePath string) (string, error) { } } } - return "", fmt.Errorf("Build file not found") + return "", errors.New("Build file not found") } } @@ -77,7 +79,7 @@ func writeChaincodePackage(spec *pb.ChaincodeSpec, tw *tar.Writer) error { } if urlLocation == "" { - return fmt.Errorf("empty url location") + return errors.New("ChaincodeSpec's path/URL cannot be empty") } if strings.LastIndex(urlLocation, "/") == len(urlLocation)-1 { diff --git a/core/chaincode/platforms/java/platform.go b/core/chaincode/platforms/java/platform.go index eae3a1bae38..abc128d4468 100644 --- a/core/chaincode/platforms/java/platform.go +++ b/core/chaincode/platforms/java/platform.go @@ -31,8 +31,8 @@ type Platform struct { //ValidateSpec validates the java chaincode specs func (javaPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error { - url, err := url.Parse(spec.ChaincodeID.Path) - if err != nil || url == nil { + path, err := url.Parse(spec.ChaincodeID.Path) + if err != nil || path == nil { return fmt.Errorf("invalid path: %s", err) }