7f734c73
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
Conrad Hoffmann <ch@bitfehler.net> — 2026-05-08 08:31:31 UTC
Commit 7f734c73acb2c577b047bcd0d9f0e5a453da91ab —
view raw patch
Parent(s):
67e65522
| File | Status | + | − |
|---|---|---|---|
errors/errors.go
|
M | +1 | -1 |