From cf341ee49aabae95f583add859ac9186e0a42bb4 Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Tue, 28 Sep 2021 07:26:34 +0000 Subject: [PATCH] Improve an error message in `InstallChaincode` In case a 'chaincode already successfully installed' error occurs when installing a chaincode, Fabric admins cannot to know the package ID. In this case, if multiple chaincode packages with the same label are installed, it is not possible to identify them later by using `queryinstalled`. So, this patch adds the package ID to the error message in the case of 'chaincode already successfully installed'. Signed-off-by: Tatsuya Sato --- core/chaincode/lifecycle/lifecycle.go | 2 +- core/chaincode/lifecycle/lifecycle_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/chaincode/lifecycle/lifecycle.go b/core/chaincode/lifecycle/lifecycle.go index d7f99932101..da507d63a2d 100644 --- a/core/chaincode/lifecycle/lifecycle.go +++ b/core/chaincode/lifecycle/lifecycle.go @@ -685,7 +685,7 @@ func (ef *ExternalFunctions) InstallChaincode(chaincodeInstallPackage []byte) (* // installed a chaincode with this package id <-buildStatus.Done() if buildStatus.Err() == nil { - return nil, errors.New("chaincode already successfully installed") + return nil, errors.Errorf("chaincode already successfully installed (package ID '%s')", packageID) } buildStatus = ef.BuildRegistry.ResetBuildStatus(packageID) } diff --git a/core/chaincode/lifecycle/lifecycle_test.go b/core/chaincode/lifecycle/lifecycle_test.go index f5dcb0e7fa8..2285f1da2fb 100644 --- a/core/chaincode/lifecycle/lifecycle_test.go +++ b/core/chaincode/lifecycle/lifecycle_test.go @@ -392,7 +392,7 @@ var _ = Describe("ExternalFunctions", func() { It("does not attempt to rebuild it itself", func() { _, err := ef.InstallChaincode([]byte("cc-package")) - Expect(err).To(MatchError("chaincode already successfully installed")) + Expect(err).To(MatchError("chaincode already successfully installed (package ID 'fake-hash')")) Expect(fakeChaincodeBuilder.BuildCallCount()).To(Equal(0)) }) })