util: add Unwrap() to error types

See-also: https://github.com/golang/go/wiki/ErrorValueFAQ#i-have-a-type-that-implements-error-and-holds-a-nested-error-how-should-i-adapt-it-to-the-new-features
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-06-30 08:43:24 +02:00 committed by mergify[bot]
parent 6d6b5bab3c
commit 8effa0cd3e

View File

@ -32,6 +32,11 @@ func (e ErrKeyNotFound) Error() string {
return e.err.Error() return e.err.Error()
} }
// Unwrap returns the encapsulated error.
func (e ErrKeyNotFound) Unwrap() error {
return e.err
}
// ErrObjectExists is returned when named omap is already present in rados // ErrObjectExists is returned when named omap is already present in rados
type ErrObjectExists struct { type ErrObjectExists struct {
objectName string objectName string
@ -43,6 +48,11 @@ func (e ErrObjectExists) Error() string {
return e.err.Error() return e.err.Error()
} }
// Unwrap returns the encapsulated error.
func (e ErrObjectExists) Unwrap() error {
return e.err
}
// ErrObjectNotFound is returned when named omap is not found in rados // ErrObjectNotFound is returned when named omap is not found in rados
type ErrObjectNotFound struct { type ErrObjectNotFound struct {
oMapName string oMapName string
@ -54,6 +64,11 @@ func (e ErrObjectNotFound) Error() string {
return e.err.Error() return e.err.Error()
} }
// Unwrap returns the encapsulated error.
func (e ErrObjectNotFound) Unwrap() error {
return e.err
}
// ErrSnapNameConflict is generated when a requested CSI snap name already exists on RBD but with // ErrSnapNameConflict is generated when a requested CSI snap name already exists on RBD but with
// different properties, and hence is in conflict with the passed in CSI volume name // different properties, and hence is in conflict with the passed in CSI volume name
type ErrSnapNameConflict struct { type ErrSnapNameConflict struct {
@ -66,6 +81,11 @@ func (e ErrSnapNameConflict) Error() string {
return e.err.Error() return e.err.Error()
} }
// Unwrap returns the encapsulated error.
func (e ErrSnapNameConflict) Unwrap() error {
return e.err
}
// NewErrSnapNameConflict returns a ErrSnapNameConflict error when CSI snap name already exists. // NewErrSnapNameConflict returns a ErrSnapNameConflict error when CSI snap name already exists.
func NewErrSnapNameConflict(name string, err error) ErrSnapNameConflict { func NewErrSnapNameConflict(name string, err error) ErrSnapNameConflict {
return ErrSnapNameConflict{name, err} return ErrSnapNameConflict{name, err}
@ -82,6 +102,11 @@ func (e ErrPoolNotFound) Error() string {
return e.Err.Error() return e.Err.Error()
} }
// Unwrap returns the encapsulated error.
func (e ErrPoolNotFound) Unwrap() error {
return e.Err
}
// NewErrPoolNotFound returns a new ErrPoolNotFound error. // NewErrPoolNotFound returns a new ErrPoolNotFound error.
func NewErrPoolNotFound(pool string, err error) ErrPoolNotFound { func NewErrPoolNotFound(pool string, err error) ErrPoolNotFound {
return ErrPoolNotFound{pool, err} return ErrPoolNotFound{pool, err}