Roger, I think you slightly misunderstood me. ;-)

It is true that `As` and `Is` methods can be used to allow `errors.As` and 
`errors.Is` to handle error types that aren't actually in the error chain.

However my question was if an `errors.Chain` function which returns details 
about the error types and values in the error chain would be a worthwhile 
addition to Go's `errors` package.

On Wednesday, March 31, 2021 at 7:33:32 PM UTC+2 rog wrote:

> On Wed, 31 Mar 2021 at 18:05, 'Michael Schaller' via golang-nuts <
> golan...@googlegroups.com> wrote:
>
>> Hi everyone,
>>
>> I often encounter deep error chains where errors are wrapped across 
>> several Go packages and that makes it often hard to find a usable error 
>> type to use with `errors.As` or `errors.Is`.
>>
>> Could it make sense to add an `errors.Chain` function to Go that returns 
>> a slice with tuples of error type (reflect.Type) and the respective error?
>>
>
> Unfortunately that's not possible in general because errors in the change 
> can implement their own `As` and `Is` methods, so an error can appear
> to have some type T in the chain (i.e. errors.As(new(T)) returns true) 
> without *actually *having that type in the chain.
>
> For example: https://play.golang.org/p/-IAKMrD8FlG
>
> It's a shame in my view, but that's what we've got.
>
>   cheers,
>     rog.
>
>
>> Quick example:
>> https://play.golang.org/p/hDW0_6P7O2Y
>>
>> Best,
>>
>> Michael
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/acab291d-21bc-4c84-a19a-7f9901cc8035n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/acab291d-21bc-4c84-a19a-7f9901cc8035n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9aed0787-8a5f-4b1b-ab18-ee654418340an%40googlegroups.com.

Reply via email to