Skip to content

Commit 0fef15c

Browse files
Avoid nil pointer exception
When the notification is nil but an error occurs and debug log level is enabled the log field was calling `notification.No`.
1 parent 99a95ec commit 0fef15c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
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)

0 commit comments

Comments
 (0)