feat(gqlerror): add Error.Is for errors.Is support - #449
Conversation
|
Thanks! I'm just thinking about this a bit. The issue title sort of buries the fact that there's an intended ripple effect, so that
Tensions I'm mulling over
|
… match Make the structural matching of Error.Is and its ripple into List.Is explicit via doc comments, and pin the List structural-match case with a test, per review discussion.
|
Good catch on the ripple effect. I kept the structural List.Is behavior and made it explicit in d2e6bd9: doc comments on both Is methods spelling out the semantics, plus a List test covering the structural match case, so the change is deliberate and pinned by tests. |
Summary
*gqlerror.Errornow implementsIs(error) bool, so two structurally-equal gqlerrors compare as equal undererrors.Is(andcmpopts.EquateErrors, which is built on it). Previouslyerrors.Isfell back to pointer identity, so two errors carrying identical fields but distinct instances never matched.Background
The gqlerror package already ships a
List.Ismethod, soError.Iscompletes that pattern; #249 requested it and a maintainer replied "Excellent idea! PR welcome!". The method declines non-*Errortargets (lettingerrors.Iskeep walking the receiver'sUnwrapchain) and, for a*Errortarget, compares the identifying fields the issue means by "the same fields":Message,Rule,Path,Locations, andExtensions. The private wrapped cause (Err) is intentionally left to the existingUnwrapchain rather than folded intoIs, and the comparison is against the direct target only (not the target's unwrap chain), matching Go'serrors.Issemantics. A nil receiver is guarded.I have:
List.Is/List.Asstyle)Closes #249