Skip to content

Commit a5cc798

Browse files
authored
Merge pull request #759 from irapandey/error_msg_fix
Replaced fmt.Errorf to errors.New for static messages
2 parents dcdd348 + df6e962 commit a5cc798

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

pkg/cloud/metadata_k8s.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cloud
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"os"
2324

@@ -43,7 +44,7 @@ var DefaultKubernetesAPIClient = func(kubeconfig string) (kubernetes.Interface,
4344
func KubernetesAPIInstanceInfo(clientset kubernetes.Interface) (*Metadata, error) {
4445
nodeName := os.Getenv("CSI_NODE_NAME")
4546
if nodeName == "" {
46-
return nil, fmt.Errorf("CSI_NODE_NAME env var not set")
47+
return nil, errors.New("CSI_NODE_NAME env var not set")
4748
}
4849
return GetInstanceInfoFromProviderID(clientset, nodeName)
4950
}

pkg/cloud/powervs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cloud
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"os"
2324
"strings"
@@ -269,7 +270,7 @@ func readCredentials() (string, error) {
269270
klog.Info("Falling back to read IBMCLOUD_API_KEY environment variable for the key")
270271
apiKey = os.Getenv("IBMCLOUD_API_KEY")
271272
if apiKey == "" {
272-
return "", fmt.Errorf("IBMCLOUD_API_KEY is not provided")
273+
return "", errors.New("IBMCLOUD_API_KEY is not provided")
273274
}
274275

275276
return apiKey, nil

pkg/driver/controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package driver
1515

1616
import (
1717
"context"
18-
"fmt"
18+
"errors"
1919
"reflect"
2020
"testing"
2121

@@ -811,7 +811,7 @@ func TestDeleteVolume(t *testing.T) {
811811
defer mockCtl.Finish()
812812

813813
mockCloud := mocks.NewMockCloud(mockCtl)
814-
mockCloud.EXPECT().DeleteDisk(gomock.Eq(req.VolumeId)).Return(fmt.Errorf("DeleteDisk could not delete volume"))
814+
mockCloud.EXPECT().DeleteDisk(gomock.Eq(req.VolumeId)).Return(errors.New("DeleteDisk could not delete volume"))
815815
mockCloud.EXPECT().GetDiskByID(gomock.Eq(req.VolumeId)).Return(nil, nil)
816816
powervsDriver := controllerService{
817817
cloud: mockCloud,
@@ -906,7 +906,7 @@ func TestControllerPublishVolume(t *testing.T) {
906906
mockCloud := mocks.NewMockCloud(mockCtl)
907907
mockCloud.EXPECT().GetPVMInstanceByID(gomock.Eq(expInstanceID)).Return(nil, nil)
908908
mockCloud.EXPECT().GetDiskByID(gomock.Eq(volumeName)).Return(&cloud.Disk{WWN: expDevicePath}, nil)
909-
mockCloud.EXPECT().IsAttached(gomock.Eq(volumeName), gomock.Eq(expInstanceID)).Return(fmt.Errorf("the disk is unattached"))
909+
mockCloud.EXPECT().IsAttached(gomock.Eq(volumeName), gomock.Eq(expInstanceID)).Return(errors.New("the disk is unattached"))
910910
mockCloud.EXPECT().AttachDisk(gomock.Eq(volumeName), gomock.Eq(expInstanceID)).Return(nil)
911911

912912
powervsDriver := controllerService{

pkg/util/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package util
1515

1616
import (
17-
"fmt"
17+
"errors"
1818
"reflect"
1919
"testing"
2020

@@ -102,7 +102,7 @@ func TestParseEndpoint(t *testing.T) {
102102
{
103103
name: "invalid endpoint",
104104
endpoint: "http://127.0.0.1",
105-
expErr: fmt.Errorf("unsupported protocol: http"),
105+
expErr: errors.New("unsupported protocol: http"),
106106
},
107107
}
108108

tests/remote/pi_resources.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package remote
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"os"
2324
"time"
@@ -205,7 +206,7 @@ func (r *Remote) createInstance(image, network string) (string, string, error) {
205206
}
206207

207208
if publicIP == "" {
208-
return "", "", fmt.Errorf("error while getting pvm instance public IP")
209+
return "", "", errors.New("error while getting pvm instance public IP")
209210
}
210211

211212
err = waitForInstanceSSH(publicIP)
@@ -250,7 +251,7 @@ func waitForInstanceHealth(insID string, ic *instance.IBMPIInstanceClient) (*mod
250251
if pvm.Fault != nil {
251252
return false, fmt.Errorf("failed to create a PowerVS instance: %s", pvm.Fault.Message)
252253
}
253-
return false, fmt.Errorf("failed to create a PowerVS instance")
254+
return false, errors.New("failed to create a PowerVS instance")
254255
}
255256
// Check for `instanceReadyStatus` health status and also the final health status "OK"
256257
if *pvm.Status == cloud.PowerVSInstanceStateACTIVE && (pvm.Health.Status == cloud.PowerVSInstanceHealthWARNING || pvm.Health.Status == cloud.PowerVSInstanceHealthOK) {

0 commit comments

Comments
 (0)