mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
util: simplify error handling
The sentinel error code had additional fields in the errors, that are used nowhere. This leads to unneccesarily complicated code. This change replaces the sentinel errors in utils with standard errors created with errors.New() and adds a simple JoinErrors() function to be able to combine sentinel errors from different code tiers. Related: #1203 Signed-off-by: Sven Anderson <sven@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
c277ed588d
commit
8393fbe40b
@ -84,7 +84,7 @@ func getMetadataPool(ctx context.Context, monitors string, cr *util.Credentials,
|
||||
}
|
||||
}
|
||||
|
||||
return "", util.ErrPoolNotFound{Pool: fsName, Err: fmt.Errorf("fsName (%s) not found in Ceph cluster", fsName)}
|
||||
return "", fmt.Errorf("%w: fsName (%s) not found in Ceph cluster", util.ErrPoolNotFound, fsName)
|
||||
}
|
||||
|
||||
// CephFilesystemDump is a representation of the main json structure returned by 'ceph fs dump'.
|
||||
@ -114,5 +114,5 @@ func getFsName(ctx context.Context, monitors string, cr *util.Credentials, fscID
|
||||
}
|
||||
}
|
||||
|
||||
return "", util.ErrPoolNotFound{Pool: string(fscID), Err: fmt.Errorf("fscID (%d) not found in Ceph cluster", fscID)}
|
||||
return "", fmt.Errorf("%w: fscID (%d) not found in Ceph cluster", util.ErrPoolNotFound, fscID)
|
||||
}
|
||||
|
@ -172,16 +172,14 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
|
||||
if err != nil {
|
||||
// if error is ErrPoolNotFound, the pool is already deleted we dont
|
||||
// need to worry about deleting subvolume or omap data, return success
|
||||
var epnf util.ErrPoolNotFound
|
||||
if errors.As(err, &epnf) {
|
||||
if errors.Is(err, util.ErrPoolNotFound) {
|
||||
klog.Warningf(util.Log(ctx, "failed to get backend volume for %s: %v"), string(volID), err)
|
||||
return &csi.DeleteVolumeResponse{}, nil
|
||||
}
|
||||
// if error is ErrKeyNotFound, then a previous attempt at deletion was complete
|
||||
// or partially complete (subvolume and imageOMap are garbage collected already), hence
|
||||
// return success as deletion is complete
|
||||
var eknf util.ErrKeyNotFound
|
||||
if errors.As(err, &eknf) {
|
||||
if errors.Is(err, util.ErrKeyNotFound) {
|
||||
return &csi.DeleteVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user