From 6d6b5bab3c42af563d96d9f49671f2c6a3483feb Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 30 Jun 2020 08:43:24 +0200 Subject: [PATCH] rbd: 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/rbd/errors.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/rbd/errors.go b/internal/rbd/errors.go index a2d32bcd9..2675562ae 100644 --- a/internal/rbd/errors.go +++ b/internal/rbd/errors.go @@ -27,6 +27,11 @@ func (e ErrImageNotFound) Error() string { return e.err.Error() } +// Unwrap returns the encapsulated error of ErrImageNotFound. +func (e ErrImageNotFound) Unwrap() error { + return e.err +} + // ErrSnapNotFound is returned when snap name passed is not found in the list of snapshots for the // given image type ErrSnapNotFound struct { @@ -39,6 +44,11 @@ func (e ErrSnapNotFound) Error() string { return e.err.Error() } +// Unwrap returns the encapsulated error of ErrSnapNotFound. +func (e ErrSnapNotFound) Unwrap() error { + return e.err +} + // ErrVolNameConflict is generated when a requested CSI volume name already exists on RBD but with // different properties, and hence is in conflict with the passed in CSI volume name type ErrVolNameConflict struct { @@ -51,6 +61,11 @@ func (e ErrVolNameConflict) Error() string { return e.err.Error() } +// Unwrap returns the encapsulated error of ErrVolNameConflict. +func (e ErrVolNameConflict) Unwrap() error { + return e.err +} + // ErrInvalidVolID is returned when a CSI passed VolumeID does not conform to any known volume ID // formats type ErrInvalidVolID struct { @@ -62,6 +77,11 @@ func (e ErrInvalidVolID) Error() string { return e.err.Error() } +// Unwrap returns the encapsulated error of ErrInvalidVolID. +func (e ErrInvalidVolID) Unwrap() error { + return e.err +} + // ErrMissingStash is returned when the image metadata stash file is not found type ErrMissingStash struct { err error @@ -72,6 +92,11 @@ func (e ErrMissingStash) Error() string { return e.err.Error() } +// Unwrap returns the encapsulated error of ErrMissingStash. +func (e ErrMissingStash) Unwrap() error { + return e.err +} + // ErrFlattenInProgress is returned when flatten is inprogess for an image type ErrFlattenInProgress struct { err error @@ -81,3 +106,8 @@ type ErrFlattenInProgress struct { func (e ErrFlattenInProgress) Error() string { return e.err.Error() } + +// Unwrap returns the encapsulated error of ErrFlattenInProgress. +func (e ErrFlattenInProgress) Unwrap() error { + return e.err +}