mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
Merge pull request #292 from thaJeztah/errors_improvements
credentials: improve errors and error-handling
This commit is contained in:
+25
-6
@@ -1,5 +1,7 @@
|
|||||||
package credentials
|
package credentials
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ErrCredentialsNotFound standardizes the not found error, so every helper returns
|
// ErrCredentialsNotFound standardizes the not found error, so every helper returns
|
||||||
// the same message and docker can handle it properly.
|
// the same message and docker can handle it properly.
|
||||||
@@ -21,6 +23,11 @@ func (errCredentialsNotFound) Error() string {
|
|||||||
return errCredentialsNotFoundMessage
|
return errCredentialsNotFoundMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotFound implements the [ErrNotFound][errdefs.ErrNotFound] interface.
|
||||||
|
//
|
||||||
|
// [errdefs.ErrNotFound]: https://pkg.go.dev/github.com/docker/docker@v24.0.1+incompatible/errdefs#ErrNotFound
|
||||||
|
func (errCredentialsNotFound) NotFound() {}
|
||||||
|
|
||||||
// NewErrCredentialsNotFound creates a new error
|
// NewErrCredentialsNotFound creates a new error
|
||||||
// for when the credentials are not in the store.
|
// for when the credentials are not in the store.
|
||||||
func NewErrCredentialsNotFound() error {
|
func NewErrCredentialsNotFound() error {
|
||||||
@@ -30,8 +37,8 @@ func NewErrCredentialsNotFound() error {
|
|||||||
// IsErrCredentialsNotFound returns true if the error
|
// IsErrCredentialsNotFound returns true if the error
|
||||||
// was caused by not having a set of credentials in a store.
|
// was caused by not having a set of credentials in a store.
|
||||||
func IsErrCredentialsNotFound(err error) bool {
|
func IsErrCredentialsNotFound(err error) bool {
|
||||||
_, ok := err.(errCredentialsNotFound)
|
var target errCredentialsNotFound
|
||||||
return ok
|
return errors.As(err, &target)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsErrCredentialsNotFoundMessage returns true if the error
|
// IsErrCredentialsNotFoundMessage returns true if the error
|
||||||
@@ -53,6 +60,12 @@ func (errCredentialsMissingServerURL) Error() string {
|
|||||||
return errCredentialsMissingServerURLMessage
|
return errCredentialsMissingServerURLMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InvalidParameter implements the [ErrInvalidParameter][errdefs.ErrInvalidParameter]
|
||||||
|
// interface.
|
||||||
|
//
|
||||||
|
// [errdefs.ErrInvalidParameter]: https://pkg.go.dev/github.com/docker/docker@v24.0.1+incompatible/errdefs#ErrInvalidParameter
|
||||||
|
func (errCredentialsMissingServerURL) InvalidParameter() {}
|
||||||
|
|
||||||
// errCredentialsMissingUsername represents an error raised
|
// errCredentialsMissingUsername represents an error raised
|
||||||
// when the credentials object has no username or when no
|
// when the credentials object has no username or when no
|
||||||
// username is provided to a credentials operation requiring
|
// username is provided to a credentials operation requiring
|
||||||
@@ -63,6 +76,12 @@ func (errCredentialsMissingUsername) Error() string {
|
|||||||
return errCredentialsMissingUsernameMessage
|
return errCredentialsMissingUsernameMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InvalidParameter implements the [ErrInvalidParameter][errdefs.ErrInvalidParameter]
|
||||||
|
// interface.
|
||||||
|
//
|
||||||
|
// [errdefs.ErrInvalidParameter]: https://pkg.go.dev/github.com/docker/docker@v24.0.1+incompatible/errdefs#ErrInvalidParameter
|
||||||
|
func (errCredentialsMissingUsername) InvalidParameter() {}
|
||||||
|
|
||||||
// NewErrCredentialsMissingServerURL creates a new error for
|
// NewErrCredentialsMissingServerURL creates a new error for
|
||||||
// errCredentialsMissingServerURL.
|
// errCredentialsMissingServerURL.
|
||||||
func NewErrCredentialsMissingServerURL() error {
|
func NewErrCredentialsMissingServerURL() error {
|
||||||
@@ -78,8 +97,8 @@ func NewErrCredentialsMissingUsername() error {
|
|||||||
// IsCredentialsMissingServerURL returns true if the error
|
// IsCredentialsMissingServerURL returns true if the error
|
||||||
// was an errCredentialsMissingServerURL.
|
// was an errCredentialsMissingServerURL.
|
||||||
func IsCredentialsMissingServerURL(err error) bool {
|
func IsCredentialsMissingServerURL(err error) bool {
|
||||||
_, ok := err.(errCredentialsMissingServerURL)
|
var target errCredentialsMissingServerURL
|
||||||
return ok
|
return errors.As(err, &target)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsCredentialsMissingServerURLMessage checks for an
|
// IsCredentialsMissingServerURLMessage checks for an
|
||||||
@@ -91,8 +110,8 @@ func IsCredentialsMissingServerURLMessage(err string) bool {
|
|||||||
// IsCredentialsMissingUsername returns true if the error
|
// IsCredentialsMissingUsername returns true if the error
|
||||||
// was an errCredentialsMissingUsername.
|
// was an errCredentialsMissingUsername.
|
||||||
func IsCredentialsMissingUsername(err error) bool {
|
func IsCredentialsMissingUsername(err error) bool {
|
||||||
_, ok := err.(errCredentialsMissingUsername)
|
var target errCredentialsMissingUsername
|
||||||
return ok
|
return errors.As(err, &target)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsCredentialsMissingUsernameMessage checks for an
|
// IsCredentialsMissingUsernameMessage checks for an
|
||||||
|
|||||||
Reference in New Issue
Block a user