1
1
package credentials
2
2
3
+ import "errors"
4
+
3
5
const (
4
6
// ErrCredentialsNotFound standardizes the not found error, so every helper returns
5
7
// the same message and docker can handle it properly.
@@ -21,6 +23,11 @@ func (errCredentialsNotFound) Error() string {
21
23
return errCredentialsNotFoundMessage
22
24
}
23
25
26
+ // NotFound implements the [ErrNotFound][errdefs.ErrNotFound] interface.
27
+ //
28
+ // [errdefs.ErrNotFound]: https://pkg.go.dev/github.com/docker/[email protected] +incompatible/errdefs#ErrNotFound
29
+ func (errCredentialsNotFound ) NotFound () {}
30
+
24
31
// NewErrCredentialsNotFound creates a new error
25
32
// for when the credentials are not in the store.
26
33
func NewErrCredentialsNotFound () error {
@@ -30,8 +37,8 @@ func NewErrCredentialsNotFound() error {
30
37
// IsErrCredentialsNotFound returns true if the error
31
38
// was caused by not having a set of credentials in a store.
32
39
func IsErrCredentialsNotFound (err error ) bool {
33
- _ , ok := err .( errCredentialsNotFound )
34
- return ok
40
+ var target errCredentialsNotFound
41
+ return errors . As ( err , & target )
35
42
}
36
43
37
44
// IsErrCredentialsNotFoundMessage returns true if the error
@@ -53,6 +60,12 @@ func (errCredentialsMissingServerURL) Error() string {
53
60
return errCredentialsMissingServerURLMessage
54
61
}
55
62
63
+ // InvalidParameter implements the [ErrInvalidParameter][errdefs.ErrInvalidParameter]
64
+ // interface.
65
+ //
66
+ // [errdefs.ErrInvalidParameter]: https://pkg.go.dev/github.com/docker/[email protected] +incompatible/errdefs#ErrInvalidParameter
67
+ func (errCredentialsMissingServerURL ) InvalidParameter () {}
68
+
56
69
// errCredentialsMissingUsername represents an error raised
57
70
// when the credentials object has no username or when no
58
71
// username is provided to a credentials operation requiring
@@ -63,6 +76,12 @@ func (errCredentialsMissingUsername) Error() string {
63
76
return errCredentialsMissingUsernameMessage
64
77
}
65
78
79
+ // InvalidParameter implements the [ErrInvalidParameter][errdefs.ErrInvalidParameter]
80
+ // interface.
81
+ //
82
+ // [errdefs.ErrInvalidParameter]: https://pkg.go.dev/github.com/docker/[email protected] +incompatible/errdefs#ErrInvalidParameter
83
+ func (errCredentialsMissingUsername ) InvalidParameter () {}
84
+
66
85
// NewErrCredentialsMissingServerURL creates a new error for
67
86
// errCredentialsMissingServerURL.
68
87
func NewErrCredentialsMissingServerURL () error {
@@ -78,8 +97,8 @@ func NewErrCredentialsMissingUsername() error {
78
97
// IsCredentialsMissingServerURL returns true if the error
79
98
// was an errCredentialsMissingServerURL.
80
99
func IsCredentialsMissingServerURL (err error ) bool {
81
- _ , ok := err .( errCredentialsMissingServerURL )
82
- return ok
100
+ var target errCredentialsMissingServerURL
101
+ return errors . As ( err , & target )
83
102
}
84
103
85
104
// IsCredentialsMissingServerURLMessage checks for an
@@ -91,8 +110,8 @@ func IsCredentialsMissingServerURLMessage(err string) bool {
91
110
// IsCredentialsMissingUsername returns true if the error
92
111
// was an errCredentialsMissingUsername.
93
112
func IsCredentialsMissingUsername (err error ) bool {
94
- _ , ok := err .( errCredentialsMissingUsername )
95
- return ok
113
+ var target errCredentialsMissingUsername
114
+ return errors . As ( err , & target )
96
115
}
97
116
98
117
// IsCredentialsMissingUsernameMessage checks for an
0 commit comments