From c030bcb0348cdaef48eb2baa6735f6b3b632fd47 Mon Sep 17 00:00:00 2001 From: Ian Howell Date: Thu, 28 May 2020 14:22:16 -0500 Subject: [PATCH] Remove AirshipError This removes the common, as it doesn't add any additional information when an error occurs Change-Id: Id67e38604445a2a044aae949d933f556bb29b05c --- pkg/config/repo.go | 4 ++-- pkg/errors/common.go | 21 +++++++-------------- pkg/remote/errors.go | 14 ++++++-------- pkg/remote/redfish/errors.go | 4 ---- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/pkg/config/repo.go b/pkg/config/repo.go index 92c9d1b80..35415f2e9 100644 --- a/pkg/config/repo.go +++ b/pkg/config/repo.go @@ -60,7 +60,7 @@ func (c *RepoCheckout) Validate() error { return ErrMutuallyExclusiveCheckout{} } if c.RemoteRef != "" { - return fmt.Errorf("Repository checkout by RemoteRef is not yet implemented\n%w", errors.ErrNotImplemented{}) + return errors.ErrNotImplemented{What: "repository checkout by RemoteRef"} } return nil } @@ -163,7 +163,7 @@ func (repo *Repository) ToAuth() (transport.AuthMethod, error) { case HTTPBasic: return &http.BasicAuth{Username: repo.Auth.Username, Password: repo.Auth.HTTPPassword}, nil default: - return nil, fmt.Errorf("Error building auth opts, repo\n%s\n: %w", repo.String(), errors.ErrNotImplemented{}) + return nil, errors.ErrNotImplemented{What: fmt.Sprintf("authtype %s", repo.Auth.Type)} } } diff --git a/pkg/errors/common.go b/pkg/errors/common.go index da1087e14..dc823461e 100644 --- a/pkg/errors/common.go +++ b/pkg/errors/common.go @@ -14,23 +14,16 @@ package errors -// AirshipError is the base error type -// used to create extended error types -// in other airshipctl packages. -type AirshipError struct { - Message string -} +import "fmt" -// Error function implements the golang -// error interface -func (ae *AirshipError) Error() string { - return ae.Message -} - -// ErrNotImplemented returned for not implemented features +// ErrNotImplemented returned for features not yet implemented type ErrNotImplemented struct { + What string } func (e ErrNotImplemented) Error() string { - return "Not implemented" + if e.What != "" { + return fmt.Sprintf("not implemented: %s", e.What) + } + return "not implemented" } diff --git a/pkg/remote/errors.go b/pkg/remote/errors.go index de8021101..a69a5d32d 100644 --- a/pkg/remote/errors.go +++ b/pkg/remote/errors.go @@ -16,8 +16,6 @@ package remote import ( "fmt" - - aerror "opendev.org/airship/airshipctl/pkg/errors" ) // TODO: This need to be refactored to match the error format used elsewhere in airshipctl @@ -25,20 +23,21 @@ import ( // GenericError provides general feedback about an error that occurred in a remote operation type GenericError struct { - aerror.AirshipError + Message string } // NewRemoteDirectErrorf retruns formatted remote direct errors func NewRemoteDirectErrorf(format string, v ...interface{}) error { - e := &GenericError{} - e.Message = fmt.Sprintf(format, v...) - return e + return &GenericError{Message: fmt.Sprintf(format, v...)} +} + +func (e GenericError) Error() string { + return e.Message } // ErrUnknownManagementType is an error that indicates the remote type specified in the airshipctl management // configuration (e.g. redfish, redfish-dell) is not supported. type ErrUnknownManagementType struct { - aerror.AirshipError Type string } @@ -49,7 +48,6 @@ func (e ErrUnknownManagementType) Error() string { // ErrMissingBootstrapInfoOption is an error that indicates a bootstrap option is missing in the airshipctl // bootstrapInfo configuration. type ErrMissingBootstrapInfoOption struct { - aerror.AirshipError What string } diff --git a/pkg/remote/redfish/errors.go b/pkg/remote/redfish/errors.go index 183bc568f..54ca0a8de 100644 --- a/pkg/remote/redfish/errors.go +++ b/pkg/remote/redfish/errors.go @@ -16,13 +16,10 @@ package redfish import ( "fmt" - - aerror "opendev.org/airship/airshipctl/pkg/errors" ) // ErrRedfishClient describes an error encountered by the go-redfish client. type ErrRedfishClient struct { - aerror.AirshipError Message string } @@ -51,7 +48,6 @@ func (e ErrOperationRetriesExceeded) Error() string { // ErrUnrecognizedRedfishResponse is a debug error that describes unexpected formats in a Redfish error response. type ErrUnrecognizedRedfishResponse struct { - aerror.AirshipError Key string }