Skip to content

Commit fe954c1

Browse files
authored
Change chained hooks nil check to correct function (#21)
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`
1 parent a3f1f92 commit fe954c1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lifecycle.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func ChainLifecycleHooks(hooks ...LifecycleHooks) LifecycleHooks {
110110
},
111111
PostReadImmediate: func(ctx context.Context, meta LifecyclePostReadImmediateMeta) {
112112
for _, h := range hooks {
113-
if h.PostRead != nil {
113+
if h.PostReadImmediate != nil {
114114
h.PostReadImmediate(ctx, meta)
115115
}
116116
}
@@ -168,7 +168,7 @@ func ChainLifecycleHooks(hooks ...LifecycleHooks) LifecycleHooks {
168168
Headers: make(map[string][]byte),
169169
}
170170
for _, h := range hooks {
171-
if h.PreProcessing != nil {
171+
if h.PreWrite != nil {
172172
var err error
173173

174174
resp, err := h.PreWrite(ctx, meta)
@@ -185,7 +185,7 @@ func ChainLifecycleHooks(hooks ...LifecycleHooks) LifecycleHooks {
185185
},
186186
PostFanout: func(ctx context.Context) {
187187
for _, h := range hooks {
188-
if h.PostRead != nil {
188+
if h.PostFanout != nil {
189189
h.PostFanout(ctx)
190190
}
191191
}

0 commit comments

Comments
 (0)