Are you confused by the semantics of `errors.Is(err1, err2)`

Hey peeps, quick question regarding errors - is anyone else confused that errors.Is(e1,e2) can return true while errors.Is(e2,e1) might return false at the same time? Seems that some ppl on my team were confuzzled by this and was wondering if it’s a more widespread issue. To me it seems like errors.Is(..) is more like errors.ContainsInChain(...) . WDYT?

You right. “Is” reports whether any error in err’s chain matches target. Maybe you co-worker is thinking about err1 == err2…

Hi @2121159i,

The “Is” relationship between errors is not commutative. It’s like saying, “every Go programmer is a human being”, which does not imply that every human being is a Go programmer.


Thanks for sharing folks, I was under the same impression.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.