Re: [go-nuts] Error Interfaces

2022-11-06 Thread Jason Phillips
Also note that in your original example you created two unique pointers to your error type. Even if the errors created using errors.New were equal, your example would never return true. https://play.golang.com/p/A7SltVZTlvW On Sunday, November 6, 2022 at 12:43:26 AM UTC-4 nikhil...@gmail.com wr

Re: [go-nuts] Error Interfaces

2022-11-05 Thread Nikhilesh Susarla
Thank you for the clarification. On Sat, Nov 5, 2022 at 10:37 PM Axel Wagner wrote: > To be clear: The recommendation is *not* to compare strings. The > recommendation is to compare errors by identity and not consider errors > created by different packages to be equal. > > If you desperately nee

Re: [go-nuts] Error Interfaces

2022-11-05 Thread 'Axel Wagner' via golang-nuts
To be clear: The recommendation is *not* to compare strings. The recommendation is to compare errors by identity and not consider errors created by different packages to be equal. If you desperately need your error to be considered "the same" as another, the most correct way would be to implement

Re: [go-nuts] Error Interfaces

2022-11-05 Thread Nikhilesh Susarla
The error is coming from other package. So, then have to compare strings. I guess On Sat, 5 Nov 2022 at 22:28, Sean Foley wrote: > If the error is created by your code, then just reuse the same one. > > See > https://cs.opensource.google/go/go/+/refs/tags/go1.19.3:src/io/io.go;drc=90b40c0496440f

Re: [go-nuts] Error Interfaces

2022-11-05 Thread Sean Foley
If the error is created by your code, then just reuse the same one. See https://cs.opensource.google/go/go/+/refs/tags/go1.19.3:src/io/io.go;drc=90b40c0496440fbd57538eb4ba303164ed923d93;l=44 If the error is created by code other than your own, and that code does not reuse the same error, then com

Re: [go-nuts] Error Interfaces

2022-11-05 Thread Nikhilesh Susarla
Oh I see. What is the best way to compare errors? Here in the above example I can do e.Error() == ErrNotFound.Error() // which returns true Is there any other way rather than string comparison ? Thank you On Sat, Nov 5, 2022 at 10:03 PM Axel Wagner wrote: > Oh and this behavior is documented, o

Re: [go-nuts] Error Interfaces

2022-11-05 Thread 'Axel Wagner' via golang-nuts
Oh and this behavior is documented, of course: https://pkg.go.dev/errors#New On Sat, Nov 5, 2022 at 5:32 PM Axel Wagner wrote: > Every invocation of `errors.New` returns a new unique error value, even if > the same error text is used. > That is intentional. It would be confusing, if package A ch

Re: [go-nuts] Error Interfaces

2022-11-05 Thread 'Axel Wagner' via golang-nuts
Every invocation of `errors.New` returns a new unique error value, even if the same error text is used. That is intentional. It would be confusing, if package A chose the same error sentinel text as package B and suddenly their sentinels compare as equal. If you want error identity between values,

[go-nuts] Error Interfaces

2022-11-05 Thread Nikhilesh Susarla
Same interface comparison https://play.golang.com/p/9hHlTDosYzz Why is the equals too still returning false? Any more details on this? Thank you -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop recei