Skip to content

Commit 20088d8

Browse files
authored
Merge pull request #719 from andyzhangx/fix-internal-error
fix: CSI function should return internal error
2 parents 7dda7ba + ff96485 commit 20088d8

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

pkg/blob/controllerserver.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
224224

225225
tags, err := util.ConvertTagsToMap(customTags)
226226
if err != nil {
227-
return nil, err
227+
return nil, status.Errorf(codes.InvalidArgument, err.Error())
228228
}
229229

230230
accountOptions := &azure.AccountOptions{
@@ -257,7 +257,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
257257
// search in cache first
258258
cache, err := d.accountSearchCache.Get(lockKey, azcache.CacheReadTypeDefault)
259259
if err != nil {
260-
return nil, err
260+
return nil, status.Errorf(codes.Internal, err.Error())
261261
}
262262
if cache != nil {
263263
accountName = cache.(string)
@@ -366,7 +366,7 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
366366
}
367367

368368
if err := d.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil {
369-
return nil, fmt.Errorf("invalid delete volume req: %v", req)
369+
return nil, status.Errorf(codes.Internal, "invalid delete volume req: %v", req)
370370
}
371371

372372
if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired {
@@ -521,7 +521,7 @@ func (d *Driver) ControllerExpandVolume(ctx context.Context, req *csi.Controller
521521
}
522522

523523
if err := d.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_EXPAND_VOLUME); err != nil {
524-
return nil, fmt.Errorf("invalid expand volume req: %v", req)
524+
return nil, status.Errorf(codes.Internal, "invalid expand volume req: %v", req)
525525
}
526526

527527
volSizeBytes := int64(req.GetCapacityRange().GetRequiredBytes())

pkg/blob/controllerserver_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func TestCreateVolume(t *testing.T) {
258258
controllerServiceCapability,
259259
}
260260
_, err := d.CreateVolume(context.Background(), req)
261-
expectedErr := fmt.Errorf("Tags 'unit-test' are invalid, the format should like: 'key1=value1,key2=value2'")
261+
expectedErr := status.Errorf(codes.InvalidArgument, "Tags 'unit-test' are invalid, the format should like: 'key1=value1,key2=value2'")
262262
if !reflect.DeepEqual(err, expectedErr) {
263263
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
264264
}
@@ -389,7 +389,7 @@ func TestDeleteVolume(t *testing.T) {
389389
VolumeId: "unit-test",
390390
}
391391
_, err := d.DeleteVolume(context.Background(), req)
392-
expectedErr := fmt.Errorf("invalid delete volume req: volume_id:\"unit-test\" ")
392+
expectedErr := status.Errorf(codes.Internal, "invalid delete volume req: volume_id:\"unit-test\" ")
393393
if !reflect.DeepEqual(err, expectedErr) {
394394
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
395395
}
@@ -724,7 +724,7 @@ func TestControllerExpandVolume(t *testing.T) {
724724
CapacityRange: &csi.CapacityRange{},
725725
}
726726
_, err := d.ControllerExpandVolume(context.Background(), req)
727-
expectedErr := fmt.Errorf("invalid expand volume req: volume_id:\"unit-test\" capacity_range:<> ")
727+
expectedErr := status.Errorf(codes.Internal, "invalid expand volume req: volume_id:\"unit-test\" capacity_range:<> ")
728728
if !reflect.DeepEqual(err, expectedErr) {
729729
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
730730
}

pkg/blob/nodeserver.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
124124
klog.Warningf("NodePublishVolume: mock mount on volumeID(%s), this is only for TESTING!!!", volumeID)
125125
if err := volumehelper.MakeDir(target, os.FileMode(mountPermissions)); err != nil {
126126
klog.Errorf("MakeDir failed on target: %s (%v)", target, err)
127-
return nil, err
127+
return nil, status.Errorf(codes.Internal, err.Error())
128128
}
129129
return &csi.NodePublishVolumeResponse{}, nil
130130
}
@@ -271,7 +271,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
271271

272272
_, accountName, _, containerName, authEnv, err := d.GetAuthEnv(ctx, volumeID, protocol, attrib, secrets)
273273
if err != nil {
274-
return nil, err
274+
return nil, status.Errorf(codes.Internal, err.Error())
275275
}
276276

277277
// replace pv/pvc name namespace metadata in subDir
@@ -341,7 +341,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
341341
klog.Warningf("NodeStageVolume: mock mount on volumeID(%s), this is only for TESTING!!!", volumeID)
342342
if err := volumehelper.MakeDir(targetPath, os.FileMode(mountPermissions)); err != nil {
343343
klog.Errorf("MakeDir failed on target: %s (%v)", targetPath, err)
344-
return nil, err
344+
return nil, status.Errorf(codes.Internal, err.Error())
345345
}
346346
return &csi.NodeStageVolumeResponse{}, nil
347347
}
@@ -354,7 +354,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
354354
}
355355

356356
if err != nil {
357-
err = fmt.Errorf("Mount failed with error: %w, output: %v", err, output)
357+
err = status.Errorf(codes.Internal, "Mount failed with error: %v, output: %v", err, output)
358358
klog.Errorf("%v", err)
359359
notMnt, mntErr := d.mounter.IsLikelyNotMountPoint(targetPath)
360360
if mntErr != nil {

0 commit comments

Comments
 (0)