Skip to content

Commit 6ac3fad

Browse files
Merge pull request #49 from hellofresh/patch/nil-panic
Avoid nil notifcation panic
2 parents 99a95ec + d06f16f commit 6ac3fad

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

driver/sql/projector_aggregate.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,22 @@ func (a *AggregateProjector) processNotification(
128128
notification *ProjectionNotification,
129129
queue ProjectionTrigger,
130130
) error {
131-
var err error
131+
var (
132+
err error
133+
logFields func(e goengine.LoggerEntry)
134+
)
132135
if notification != nil {
133136
err = a.executor.Execute(ctx, notification)
137+
logFields = func(e goengine.LoggerEntry) {
138+
e.Error(err)
139+
e.Int64("notification.no", notification.No)
140+
e.String("notification.aggregate_id", notification.AggregateID)
141+
}
134142
} else {
135143
err = a.triggerOutOfSyncProjections(ctx, queue)
144+
logFields = func(e goengine.LoggerEntry) {
145+
e.Error(err)
146+
}
136147
}
137148

138149
// No error occurred during projection so return
@@ -141,11 +152,6 @@ func (a *AggregateProjector) processNotification(
141152
}
142153

143154
// Resolve the action to take based on the error that occurred
144-
logFields := func(e goengine.LoggerEntry) {
145-
e.Error(err)
146-
e.Int64("notification.no", notification.No)
147-
e.String("notification.aggregate_id", notification.AggregateID)
148-
}
149155
switch resolveErrorAction(a.projectionErrorHandler, notification, err) {
150156
case errorFail:
151157
a.logger.Debug("ProcessHandler->ErrorHandler: marking projection as failed", logFields)

mocks/gomod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
package mocks
44

55
import (
6-
_ "github.com/golang/mock/mockgen/model"
6+
_ "github.com/golang/mock/mockgen"
77
)

0 commit comments

Comments
 (0)