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 <axel.wagner...@googlemail.com> wrote: > 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 <axel.wagner...@googlemail.com> > 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 chose the same >> error sentinel text as package B and suddenly their sentinels compare as >> equal. >> If you want error identity between values, you have to actually copy the >> error value (or implement your own, which may very well not do it this way). >> >> On Sat, Nov 5, 2022 at 5:29 PM Nikhilesh Susarla <nikhilesh1...@gmail.com> >> wrote: >> >>> >>> 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 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/ee3d53d3-d3c8-4a3b-801a-af6060316e3an%40googlegroups.com >>> <https://groups.google.com/d/msgid/golang-nuts/ee3d53d3-d3c8-4a3b-801a-af6060316e3an%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/CAMt-viXeFOgh42DtvD4cJiEvhUDR-PaD8GvOEDfuytLdeKE4GQ%40mail.gmail.com.