Skip to content

Commit dbfb389

Browse files
committed
credentials: use errors.As() to match error-types
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent bd83e02 commit dbfb389

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

credentials/error.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package credentials
22

3+
import "errors"
4+
35
const (
46
// ErrCredentialsNotFound standardizes the not found error, so every helper returns
57
// the same message and docker can handle it properly.
@@ -30,8 +32,8 @@ func NewErrCredentialsNotFound() error {
3032
// IsErrCredentialsNotFound returns true if the error
3133
// was caused by not having a set of credentials in a store.
3234
func IsErrCredentialsNotFound(err error) bool {
33-
_, ok := err.(errCredentialsNotFound)
34-
return ok
35+
var target errCredentialsNotFound
36+
return errors.As(err, &target)
3537
}
3638

3739
// IsErrCredentialsNotFoundMessage returns true if the error
@@ -78,8 +80,8 @@ func NewErrCredentialsMissingUsername() error {
7880
// IsCredentialsMissingServerURL returns true if the error
7981
// was an errCredentialsMissingServerURL.
8082
func IsCredentialsMissingServerURL(err error) bool {
81-
_, ok := err.(errCredentialsMissingServerURL)
82-
return ok
83+
var target errCredentialsMissingServerURL
84+
return errors.As(err, &target)
8385
}
8486

8587
// IsCredentialsMissingServerURLMessage checks for an
@@ -91,8 +93,8 @@ func IsCredentialsMissingServerURLMessage(err string) bool {
9193
// IsCredentialsMissingUsername returns true if the error
9294
// was an errCredentialsMissingUsername.
9395
func IsCredentialsMissingUsername(err error) bool {
94-
_, ok := err.(errCredentialsMissingUsername)
95-
return ok
96+
var target errCredentialsMissingUsername
97+
return errors.As(err, &target)
9698
}
9799

98100
// IsCredentialsMissingUsernameMessage checks for an

0 commit comments

Comments
 (0)