@@ -34,7 +34,6 @@ func newLink(err error, prefix string, skipFrames int) *Link {
3434		Prefix : prefix ,
3535		Source : runtimeext .StackLevel (skipFrames ),
3636	}
37- 
3837}
3938
4039// Chain contains the chained errors, the links, of the chains if you will 
@@ -214,7 +213,16 @@ func (c Chain) Unwrap() error {
214213
215214// Is reports whether any error in error chain matches target. 
216215func  (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 )
218226}
219227
220228// 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 {
234242// As panics if target is not a non-nil pointer to either a type that implements 
235243// error, or to any interface type. 
236244func  (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 )
238249}
239250
240251func  defaultFormatFn (c  Chain ) string  {
0 commit comments