File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package redis
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"io"
6
7
"net"
7
8
"strings"
@@ -15,11 +16,11 @@ var ErrClosed = pool.ErrClosed
15
16
16
17
// HasErrorPrefix checks if the err is a Redis error and the message contains a prefix.
17
18
func HasErrorPrefix (err error , prefix string ) bool {
18
- err , ok := err .( Error )
19
- if ! ok {
19
+ var rErr Error
20
+ if ! errors . As ( err , & rErr ) {
20
21
return false
21
22
}
22
- msg := err .Error ()
23
+ msg := rErr .Error ()
23
24
msg = strings .TrimPrefix (msg , "ERR " ) // KVRocks adds such prefix
24
25
return strings .HasPrefix (msg , prefix )
25
26
}
Original file line number Diff line number Diff line change @@ -558,4 +558,24 @@ var _ = Describe("Hook", func() {
558
558
"hook-1-process-end" ,
559
559
}))
560
560
})
561
+
562
+ It ("wrapped error in a hook" , func () {
563
+ client .AddHook (& hook {
564
+ processHook : func (hook redis.ProcessHook ) redis.ProcessHook {
565
+ return func (ctx context.Context , cmd redis.Cmder ) error {
566
+ if err := hook (ctx , cmd ); err != nil {
567
+ return fmt .Errorf ("wrapped error: %w" , err )
568
+ }
569
+ return nil
570
+ }
571
+ },
572
+ })
573
+ client .ScriptFlush (ctx )
574
+
575
+ script := redis .NewScript (`return 'Script and hook'` )
576
+
577
+ cmd := script .Run (ctx , client , nil )
578
+ Expect (cmd .Err ()).NotTo (HaveOccurred ())
579
+ Expect (cmd .Val ()).To (Equal ("Script and hook" ))
580
+ })
561
581
})
You can’t perform that action at this time.
0 commit comments