mirror of
https://github.com/redis/go-redis.git
synced 2025-11-26 06:23:09 +03:00
feat(errors): Introduce typed errors (#3602)
* typed errors * add error documentation * backwards compatibility * update readme, remove Is methods * Update internal/proto/redis_errors.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update internal/proto/redis_errors.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * support error wrapping for io and context errors * use unwrapping of errors in push for consistency * add common error types * fix test * fix flaky test * add comments in the example --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -2,12 +2,12 @@ package redis_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
. "github.com/bsm/ginkgo/v2"
|
||||
. "github.com/bsm/gomega"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/redis/go-redis/v9/internal/proto"
|
||||
)
|
||||
|
||||
type testTimeout struct {
|
||||
@@ -39,12 +39,13 @@ var _ = Describe("error", func() {
|
||||
context.Canceled: false,
|
||||
context.DeadlineExceeded: false,
|
||||
redis.ErrPoolTimeout: true,
|
||||
errors.New("ERR max number of clients reached"): true,
|
||||
errors.New("LOADING Redis is loading the dataset in memory"): true,
|
||||
errors.New("READONLY You can't write against a read only replica"): true,
|
||||
errors.New("CLUSTERDOWN The cluster is down"): true,
|
||||
errors.New("TRYAGAIN Command cannot be processed, please try again"): true,
|
||||
errors.New("other"): false,
|
||||
// Use typed errors instead of plain errors.New()
|
||||
proto.ParseErrorReply([]byte("-ERR max number of clients reached")): true,
|
||||
proto.ParseErrorReply([]byte("-LOADING Redis is loading the dataset in memory")): true,
|
||||
proto.ParseErrorReply([]byte("-READONLY You can't write against a read only replica")): true,
|
||||
proto.ParseErrorReply([]byte("-CLUSTERDOWN The cluster is down")): true,
|
||||
proto.ParseErrorReply([]byte("-TRYAGAIN Command cannot be processed, please try again")): true,
|
||||
proto.ParseErrorReply([]byte("-ERR other")): false,
|
||||
}
|
||||
|
||||
for err, expected := range data {
|
||||
|
||||
Reference in New Issue
Block a user