From 7f734c73acb2c577b047bcd0d9f0e5a453da91ab Mon Sep 17 00:00:00 2001 From: Conrad Hoffmann Date: Fri, 8 May 2026 10:31:31 +0200 Subject: [PATCH] errors: fix comparison in errors.Is() The code operates compares two values of compile-time type `any`. The common use case however is to compare an error from `client.Do()` to one of the reference errors, for example: if errors.Is(err, errors.ErrNotFound) { ... } However, due to how the reference errors are constructed, their error codes are of runtime-type `errors.ErrorCode`, whereas anything that got parsed from a JSON response by `gqlerrors` will always be of runtime-type `string`. Hence, Go will consider the two instances not equal at runtime. Here [1] is little playground example demonstrating the behavior. To fix it, simply cast the special error type to back to string before putting it in the map. [1]: https://go.dev/play/p/pzxuhnnIeIK --- errors/errors.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errors/errors.go b/errors/errors.go index c5885d6991fe0334cd0b1e131977c87bb2d65c48..23fd7de208afc764c33091c2d578b3af281ea116 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -13,7 +13,7 @@ type ErrorCode string func New(code ErrorCode, message string) *gqlerror.Error { return &gqlerror.Error{ Message: message, - Extensions: map[string]any{"code": code}, + Extensions: map[string]any{"code": string(code)}, } }