@@ -34,7 +34,6 @@ func newLink(err error, prefix string, skipFrames int) *Link {
34
34
Prefix : prefix ,
35
35
Source : runtimeext .StackLevel (skipFrames ),
36
36
}
37
-
38
37
}
39
38
40
39
// Chain contains the chained errors, the links, of the chains if you will
@@ -214,7 +213,16 @@ func (c Chain) Unwrap() error {
214
213
215
214
// Is reports whether any error in error chain matches target.
216
215
func (c Chain ) Is (target error ) bool {
217
- return stderrors .Is (c [len (c )- 1 ].Err , target )
216
+ if len (c ) == 0 {
217
+ return false
218
+ }
219
+ if innerErr , ok := target .(Chain ); ok {
220
+ if len (innerErr ) == 0 {
221
+ return false
222
+ }
223
+ target = innerErr [0 ].Err
224
+ }
225
+ return stderrors .Is (c [0 ].Err , target )
218
226
}
219
227
220
228
// As finds the first error in the error chain that matches target, and if so, sets
@@ -234,7 +242,10 @@ func (c Chain) Is(target error) bool {
234
242
// As panics if target is not a non-nil pointer to either a type that implements
235
243
// error, or to any interface type.
236
244
func (c Chain ) As (target any ) bool {
237
- return stderrors .As (c [len (c )- 1 ].Err , target )
245
+ if len (c ) == 0 {
246
+ return false
247
+ }
248
+ return stderrors .As (c [0 ].Err , target )
238
249
}
239
250
240
251
func defaultFormatFn (c Chain ) string {
0 commit comments