Skip to content

Commit

Permalink
Change chained hooks nil check to correct function (#21)
Browse files Browse the repository at this point in the history
The `nil` check was incorrect, resulting in a panic if the following
conditions hold true:
1. You have a `PostRead` hook func defined
2. You don't have a `PostReadImmediate` hook func defined
3. You use `ChainLifecycleHooks` to use multiple hooks

`PostRead` --> `PostReadImmediate`


Additionally, a few other hook functions had what I believe are
incorrect nil checks.
- `PreWrite`: Was checking if `PreProcessing` was `nil` instead of
`PreWrite`
- `PostFanout`: Was check if `PostRead` was `nil` instead of
`PostFanout`
  • Loading branch information
shivshav authored Dec 19, 2024
1 parent a3f1f92 commit fe954c1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func ChainLifecycleHooks(hooks ...LifecycleHooks) LifecycleHooks {
},
PostReadImmediate: func(ctx context.Context, meta LifecyclePostReadImmediateMeta) {
for _, h := range hooks {
if h.PostRead != nil {
if h.PostReadImmediate != nil {
h.PostReadImmediate(ctx, meta)
}
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func ChainLifecycleHooks(hooks ...LifecycleHooks) LifecycleHooks {
Headers: make(map[string][]byte),
}
for _, h := range hooks {
if h.PreProcessing != nil {
if h.PreWrite != nil {
var err error

resp, err := h.PreWrite(ctx, meta)
Expand All @@ -185,7 +185,7 @@ func ChainLifecycleHooks(hooks ...LifecycleHooks) LifecycleHooks {
},
PostFanout: func(ctx context.Context) {
for _, h := range hooks {
if h.PostRead != nil {
if h.PostFanout != nil {
h.PostFanout(ctx)
}
}
Expand Down

0 comments on commit fe954c1

Please sign in to comment.