From 8effa0cd3eafec0ba7bc4fa8dd7c2a610509b86e Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 30 Jun 2020 08:43:24 +0200 Subject: [PATCH] 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 --- internal/util/errors.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/internal/util/errors.go b/internal/util/errors.go index 45fd20b1f..883c20997 100644 --- a/internal/util/errors.go +++ b/internal/util/errors.go @@ -32,6 +32,11 @@ func (e ErrKeyNotFound) Error() string { 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 type ErrObjectExists struct { objectName string @@ -43,6 +48,11 @@ func (e ErrObjectExists) Error() string { 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 type ErrObjectNotFound struct { oMapName string @@ -54,6 +64,11 @@ func (e ErrObjectNotFound) Error() string { 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 // different properties, and hence is in conflict with the passed in CSI volume name type ErrSnapNameConflict struct { @@ -66,6 +81,11 @@ func (e ErrSnapNameConflict) Error() string { 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. func NewErrSnapNameConflict(name string, err error) ErrSnapNameConflict { return ErrSnapNameConflict{name, err} @@ -82,6 +102,11 @@ func (e ErrPoolNotFound) Error() string { return e.Err.Error() } +// Unwrap returns the encapsulated error. +func (e ErrPoolNotFound) Unwrap() error { + return e.Err +} + // NewErrPoolNotFound returns a new ErrPoolNotFound error. func NewErrPoolNotFound(pool string, err error) ErrPoolNotFound { return ErrPoolNotFound{pool, err}