-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from thaJeztah/errors_improvements
credentials: improve errors and error-handling
- Loading branch information
Showing
1 changed file
with
25 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package credentials | ||
|
||
import "errors" | ||
|
||
const ( | ||
// ErrCredentialsNotFound standardizes the not found error, so every helper returns | ||
// the same message and docker can handle it properly. | ||
|
@@ -21,6 +23,11 @@ func (errCredentialsNotFound) Error() string { | |
return errCredentialsNotFoundMessage | ||
} | ||
|
||
// NotFound implements the [ErrNotFound][errdefs.ErrNotFound] interface. | ||
// | ||
// [errdefs.ErrNotFound]: https://pkg.go.dev/github.com/docker/[email protected]+incompatible/errdefs#ErrNotFound | ||
func (errCredentialsNotFound) NotFound() {} | ||
|
||
// NewErrCredentialsNotFound creates a new error | ||
// for when the credentials are not in the store. | ||
func NewErrCredentialsNotFound() error { | ||
|
@@ -30,8 +37,8 @@ func NewErrCredentialsNotFound() error { | |
// IsErrCredentialsNotFound returns true if the error | ||
// was caused by not having a set of credentials in a store. | ||
func IsErrCredentialsNotFound(err error) bool { | ||
_, ok := err.(errCredentialsNotFound) | ||
return ok | ||
var target errCredentialsNotFound | ||
return errors.As(err, &target) | ||
} | ||
|
||
// IsErrCredentialsNotFoundMessage returns true if the error | ||
|
@@ -53,6 +60,12 @@ func (errCredentialsMissingServerURL) Error() string { | |
return errCredentialsMissingServerURLMessage | ||
} | ||
|
||
// InvalidParameter implements the [ErrInvalidParameter][errdefs.ErrInvalidParameter] | ||
// interface. | ||
// | ||
// [errdefs.ErrInvalidParameter]: https://pkg.go.dev/github.com/docker/[email protected]+incompatible/errdefs#ErrInvalidParameter | ||
func (errCredentialsMissingServerURL) InvalidParameter() {} | ||
|
||
// errCredentialsMissingUsername represents an error raised | ||
// when the credentials object has no username or when no | ||
// username is provided to a credentials operation requiring | ||
|
@@ -63,6 +76,12 @@ func (errCredentialsMissingUsername) Error() string { | |
return errCredentialsMissingUsernameMessage | ||
} | ||
|
||
// InvalidParameter implements the [ErrInvalidParameter][errdefs.ErrInvalidParameter] | ||
// interface. | ||
// | ||
// [errdefs.ErrInvalidParameter]: https://pkg.go.dev/github.com/docker/[email protected]+incompatible/errdefs#ErrInvalidParameter | ||
func (errCredentialsMissingUsername) InvalidParameter() {} | ||
|
||
// NewErrCredentialsMissingServerURL creates a new error for | ||
// errCredentialsMissingServerURL. | ||
func NewErrCredentialsMissingServerURL() error { | ||
|
@@ -78,8 +97,8 @@ func NewErrCredentialsMissingUsername() error { | |
// IsCredentialsMissingServerURL returns true if the error | ||
// was an errCredentialsMissingServerURL. | ||
func IsCredentialsMissingServerURL(err error) bool { | ||
_, ok := err.(errCredentialsMissingServerURL) | ||
return ok | ||
var target errCredentialsMissingServerURL | ||
return errors.As(err, &target) | ||
} | ||
|
||
// IsCredentialsMissingServerURLMessage checks for an | ||
|
@@ -91,8 +110,8 @@ func IsCredentialsMissingServerURLMessage(err string) bool { | |
// IsCredentialsMissingUsername returns true if the error | ||
// was an errCredentialsMissingUsername. | ||
func IsCredentialsMissingUsername(err error) bool { | ||
_, ok := err.(errCredentialsMissingUsername) | ||
return ok | ||
var target errCredentialsMissingUsername | ||
return errors.As(err, &target) | ||
} | ||
|
||
// IsCredentialsMissingUsernameMessage checks for an | ||
|