I have not done much with the new errors stuff, but I'll try to help. 

I assume you have read https://github.com/golang/go/wiki/ErrorValueFAQ  and 
https://blog.golang.org/go1.13-errors. There may be other posts as well. 

These new error functions, Is() and As() are about error types. It looks 
like you are trying to transform an error of type PathErr into another 
error of type PathErr with a different value. That's not how it works. 

I think most of the time As() will work because the error wraps another 
error of a different type. In that case the error should implement Unwrap() 
not As(). If your error encapsulates multiple error types, then you would 
need to implement As(). At least that is my understanding. For example, 
taking your code, and modifying it, so that PathErr can also be treated as 
an OtherErr could look like https://play.golang.org/p/qa4VU0PEP3v. But 
again, since there is only one type encompassed in PathErr, I think this 
might be more easily done with Unwrap like this: 
https://play.golang.org/p/v4gDgtlNxcQ

Good luck. 
 

On Thursday, October 24, 2019 at 4:26:25 AM UTC-4, Gert wrote:
>
> Hi, I fail to understand how the custom As is suppose to work?
>
> see example https://play.golang.org/p/tjuItX5dHoJ
>
>

-- 
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/05bbe1b9-ae29-4add-acff-970f03dc3da5%40googlegroups.com.

Reply via email to