From bf71cd1766d8620a8cbe0c2feb2f90e5f8be1da6 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 27 Nov 2023 15:41:27 +0100 Subject: [PATCH] missing handler handling --- src/udi/dispatcher/dispatcher.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/udi/dispatcher/dispatcher.go b/src/udi/dispatcher/dispatcher.go index 6cdee10..f543bf8 100644 --- a/src/udi/dispatcher/dispatcher.go +++ b/src/udi/dispatcher/dispatcher.go @@ -27,7 +27,7 @@ func InputDispatcher() { for { select { case message := <- mqtt.InputChannel: - log.Printf("Message arrived in inputDispatcher, topic: %s, payload: %s\n", message.Topic, message.Payload) + log.Printf("Message arrived in inputDispatcher, topic: %s\n", message.Topic) for _, mapping := range config.Config.TopicMappings { log.Printf("Testing %s -> %s", mapping.Topics, mapping.Handler) @@ -35,8 +35,12 @@ func InputDispatcher() { log.Printf("Testing %s in %s", message.Topic, subscribedTopic) if mqtt.TopicMatchesSubscription(message.Topic, subscribedTopic) { log.Printf("Handle message in handler %s", mapping.Handler) - handler := handlerMap[mapping.Handler] - handler.Handle(message.Topic, string(message.Payload)) + handler, exists := handlerMap[mapping.Handler] + if exists { + handler.Handle(message.Topic, string(message.Payload)) + } else { + log.Printf("Handler not found, message is lost") + } } else { log.Printf("no match") }