mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 10:53: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
@ -37,7 +37,7 @@ func getOMapValues(
|
||||
// fetch and configure the rados ioctx
|
||||
ioctx, err := conn.conn.GetIoctx(poolName)
|
||||
if err != nil {
|
||||
return nil, omapPoolError(poolName, err)
|
||||
return nil, omapPoolError(err)
|
||||
}
|
||||
defer ioctx.Destroy()
|
||||
|
||||
@ -66,7 +66,7 @@ func getOMapValues(
|
||||
klog.Errorf(
|
||||
util.Log(ctx, "omap not found (pool=%q, namespace=%q, name=%q): %v"),
|
||||
poolName, namespace, oid, err)
|
||||
return nil, util.NewErrKeyNotFound(oid, err)
|
||||
return nil, util.JoinErrors(util.ErrKeyNotFound, err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@ -83,7 +83,7 @@ func removeMapKeys(
|
||||
// fetch and configure the rados ioctx
|
||||
ioctx, err := conn.conn.GetIoctx(poolName)
|
||||
if err != nil {
|
||||
return omapPoolError(poolName, err)
|
||||
return omapPoolError(err)
|
||||
}
|
||||
defer ioctx.Destroy()
|
||||
|
||||
@ -118,7 +118,7 @@ func setOMapKeys(
|
||||
// fetch and configure the rados ioctx
|
||||
ioctx, err := conn.conn.GetIoctx(poolName)
|
||||
if err != nil {
|
||||
return omapPoolError(poolName, err)
|
||||
return omapPoolError(err)
|
||||
}
|
||||
defer ioctx.Destroy()
|
||||
|
||||
@ -142,9 +142,9 @@ func setOMapKeys(
|
||||
return nil
|
||||
}
|
||||
|
||||
func omapPoolError(poolName string, err error) error {
|
||||
func omapPoolError(err error) error {
|
||||
if errors.Is(err, rados.ErrNotFound) {
|
||||
return util.NewErrPoolNotFound(poolName, err)
|
||||
return util.JoinErrors(util.ErrPoolNotFound, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user