Skip to content

Commit

Permalink
Call all After* hooks and return first error
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Jul 9, 2019
1 parent 69cf7e5 commit e3bb77e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ func (hs hooks) beforeProcess(ctx context.Context, cmd Cmder) (context.Context,
}

func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) (context.Context, error) {
var firstErr error
for _, h := range hs.hooks {
var err error
ctx, err = h.AfterProcess(ctx, cmd)
if err != nil {
return nil, err
if err != nil && firstErr == nil {
firstErr = err
}
}
return ctx, nil
return ctx, firstErr
}

func (hs hooks) processPipeline(
Expand Down Expand Up @@ -106,14 +107,15 @@ func (hs hooks) beforeProcessPipeline(ctx context.Context, cmds []Cmder) (contex
}

func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error) {
var firstErr error
for _, h := range hs.hooks {
var err error
ctx, err = h.AfterProcessPipeline(ctx, cmds)
if err != nil {
return nil, err
if err != nil && firstErr == nil {
firstErr = err
}
}
return ctx, nil
return ctx, firstErr
}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit e3bb77e

Please sign in to comment.