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
22
33import (
44 "context"
5+ "errors"
56 "io"
67 "net"
78 "strings"
@@ -15,11 +16,11 @@ var ErrClosed = pool.ErrClosed
1516
1617// HasErrorPrefix checks if the err is a Redis error and the message contains a prefix.
1718func HasErrorPrefix (err error , prefix string ) bool {
18- err , ok := err .( Error )
19- if ! ok {
19+ var rErr Error
20+ if ! errors . As ( err , & rErr ) {
2021 return false
2122 }
22- msg := err .Error ()
23+ msg := rErr .Error ()
2324 msg = strings .TrimPrefix (msg , "ERR " ) // KVRocks adds such prefix
2425 return strings .HasPrefix (msg , prefix )
2526}
Original file line number Diff line number Diff line change @@ -558,4 +558,24 @@ var _ = Describe("Hook", func() {
558558 "hook-1-process-end" ,
559559 }))
560560 })
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+ })
561581})
You can’t perform that action at this time.
0 commit comments