@@ -139,20 +139,28 @@ type errAlreadyExists struct{}
139139
140140func (errAlreadyExists ) Error () string { return "already exists" }
141141
142+ func (errAlreadyExists ) AlreadyExists () {}
143+
142144func (e errAlreadyExists ) WithMessage (msg string ) error {
143145 return customMessage {e , msg }
144146}
145147
148+ type alreadyExists interface {
149+ AlreadyExists ()
150+ }
151+
146152// IsAlreadyExists returns true if the error is due to an already existing
147153// metadata item
148154func IsAlreadyExists (err error ) bool {
149- return errors .Is (err , ErrAlreadyExists )
155+ return errors .Is (err , ErrAlreadyExists ) || isInterface [ alreadyExists ]( err )
150156}
151157
152158type errPermissionDenied struct {}
153159
154160func (errPermissionDenied ) Error () string { return "permission denied" }
155161
162+ func (errPermissionDenied ) Forbidden () {}
163+
156164func (e errPermissionDenied ) WithMessage (msg string ) error {
157165 return customMessage {e , msg }
158166}
@@ -172,28 +180,40 @@ type errResourceExhausted struct{}
172180
173181func (errResourceExhausted ) Error () string { return "resource exhausted" }
174182
183+ func (errResourceExhausted ) ResourceExhausted () {}
184+
175185func (e errResourceExhausted ) WithMessage (msg string ) error {
176186 return customMessage {e , msg }
177187}
178188
189+ type resourceExhausted interface {
190+ ResourceExhausted ()
191+ }
192+
179193// IsResourceExhausted returns true if the error is due to
180194// a lack of resources or too many attempts.
181195func IsResourceExhausted (err error ) bool {
182- return errors .Is (err , errResourceExhausted {})
196+ return errors .Is (err , errResourceExhausted {}) || isInterface [ resourceExhausted ]( err )
183197}
184198
185199type errFailedPrecondition struct {}
186200
187201func (e errFailedPrecondition ) Error () string { return "failed precondition" }
188202
203+ func (errFailedPrecondition ) FailedPrecondition () {}
204+
189205func (e errFailedPrecondition ) WithMessage (msg string ) error {
190206 return customMessage {e , msg }
191207}
192208
209+ type failedPrecondition interface {
210+ FailedPrecondition ()
211+ }
212+
193213// IsFailedPrecondition returns true if an operation could not proceed due to
194214// the lack of a particular condition
195215func IsFailedPrecondition (err error ) bool {
196- return errors .Is (err , errFailedPrecondition {})
216+ return errors .Is (err , errFailedPrecondition {}) || isInterface [ failedPrecondition ]( err )
197217}
198218
199219type errConflict struct {}
@@ -242,27 +262,39 @@ type errAborted struct{}
242262
243263func (errAborted ) Error () string { return "aborted" }
244264
265+ func (errAborted ) Aborted () {}
266+
245267func (e errAborted ) WithMessage (msg string ) error {
246268 return customMessage {e , msg }
247269}
248270
271+ type aborted interface {
272+ Aborted ()
273+ }
274+
249275// IsAborted returns true if an operation was aborted.
250276func IsAborted (err error ) bool {
251- return errors .Is (err , errAborted {})
277+ return errors .Is (err , errAborted {}) || isInterface [ aborted ]( err )
252278}
253279
254280type errOutOfRange struct {}
255281
256282func (errOutOfRange ) Error () string { return "out of range" }
257283
284+ func (errOutOfRange ) OutOfRange () {}
285+
258286func (e errOutOfRange ) WithMessage (msg string ) error {
259287 return customMessage {e , msg }
260288}
261289
290+ type outOfRange interface {
291+ OutOfRange ()
292+ }
293+
262294// IsOutOfRange returns true if an operation could not proceed due
263295// to data being out of the expected range.
264296func IsOutOfRange (err error ) bool {
265- return errors .Is (err , errOutOfRange {})
297+ return errors .Is (err , errOutOfRange {}) || isInterface [ outOfRange ]( err )
266298}
267299
268300type errNotImplemented struct {}
0 commit comments