rbd: return more descriptive error

updated GetVolumeByID to return more
descriptive error so that caller no
need to add more details in
the error message.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2024-07-29 12:51:32 +02:00 committed by mergify[bot]
parent 8fa3ac9fb3
commit a243cf52d4

View File

@ -124,7 +124,18 @@ func (mgr *rbdManager) GetVolumeByID(ctx context.Context, id string) (types.Volu
volume, err := GenVolFromVolID(ctx, id, creds, mgr.secrets) volume, err := GenVolFromVolID(ctx, id, creds, mgr.secrets)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get volume from id %q: %w", id, err) switch {
case errors.Is(err, ErrImageNotFound):
err = fmt.Errorf("volume %s not found: %w", id, err)
return nil, err
case errors.Is(err, util.ErrPoolNotFound):
err = fmt.Errorf("pool %s not found for %s: %w", volume.Pool, id, err)
return nil, err
default:
return nil, fmt.Errorf("failed to get volume from id %q: %w", id, err)
}
} }
return volume, nil return volume, nil