From db53b1f43936898186a4b2e43d8193c5cd6c749f Mon Sep 17 00:00:00 2001 From: umagnus Date: Tue, 28 Nov 2023 07:00:20 +0000 Subject: [PATCH] improve attach error message --- pkg/azuredisk/controllerserver.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/azuredisk/controllerserver.go b/pkg/azuredisk/controllerserver.go index 19fc687c7e..feace6cdb4 100644 --- a/pkg/azuredisk/controllerserver.go +++ b/pkg/azuredisk/controllerserver.go @@ -49,6 +49,7 @@ import ( const ( waitForSnapshotReadyInterval = 5 * time.Second waitForSnapshotReadyTimeout = 10 * time.Minute + maxErrMsgLength = 990 ) // listVolumeStatus explains the return status of `listVolumesByResourceGroup` @@ -463,7 +464,11 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle } if err != nil { klog.Errorf("Attach volume %s to instance %s failed with %v", diskURI, nodeName, err) - return nil, status.Errorf(codes.Internal, "Attach volume %s to instance %s failed with %v", diskURI, nodeName, err) + errMsg := fmt.Sprintf("Attach volume %s to instance %s failed with %v", diskURI, nodeName, err) + if len(errMsg) > maxErrMsgLength { + errMsg = errMsg[:maxErrMsgLength] + } + return nil, status.Errorf(codes.Internal, errMsg) } } klog.V(2).Infof("attach volume %s to node %s successfully", diskURI, nodeName) @@ -510,7 +515,12 @@ func (d *Driver) ControllerUnpublishVolume(ctx context.Context, req *csi.Control if strings.Contains(err.Error(), consts.ErrDiskNotFound) { klog.Warningf("volume %s already detached from node %s", diskURI, nodeID) } else { - return nil, status.Errorf(codes.Internal, "Could not detach volume %s from node %s: %v", diskURI, nodeID, err) + klog.Errorf("Could not detach volume %s from node %s: %v", diskURI, nodeID, err) + errMsg := fmt.Sprintf("Could not detach volume %s from node %s: %v", diskURI, nodeID, err) + if len(errMsg) > maxErrMsgLength { + errMsg = errMsg[:maxErrMsgLength] + } + return nil, status.Errorf(codes.Internal, errMsg) } } klog.V(2).Infof("detach volume %s from node %s successfully", diskURI, nodeID)