Skip to content

Commit 5835229

Browse files
committed
[executor] Prevent crash on bad incoming message
1 parent d44acea commit 5835229

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

executor/handlers.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,17 @@ func handleMessageEvent(state *internalState, data []byte) (err error) {
180180
var cmd *executorcmd.ExecutorCommand_Transition
181181
cmd, err = activeTask.UnmarshalTransition(data)
182182
if err != nil {
183-
log.WithFields(logrus.Fields{
184-
"name": cmd.Name,
185-
"message": string(data[:]),
186-
"error": err.Error(),
187-
}).
183+
fields := logrus.Fields{
184+
"error": err.Error(),
185+
}
186+
if cmd != nil {
187+
fields["name"] = cmd.Name
188+
}
189+
if len(data) > 0 {
190+
fields["message"] = string(data[:])
191+
}
192+
193+
log.WithFields(fields).
188194
Error("cannot unmarshal incoming MESSAGE")
189195
return
190196
}

0 commit comments

Comments
 (0)