diff --git a/lib/ClusterShell/Communication.py b/lib/ClusterShell/Communication.py
index d817f0ba..2fe0d696 100644
--- a/lib/ClusterShell/Communication.py
+++ b/lib/ClusterShell/Communication.py
@@ -142,11 +142,15 @@ def _draft_new(self, attributes):
RoutingMessage.ident: RoutingMessage,
}
try:
- msg_type = attributes['type']
+ msg_type = attributes.get('type')
# select the good constructor
ctor = ctors_map[msg_type]
except KeyError:
- raise MessageProcessingError('Unknown message type')
+ if msg_type:
+ ex_msg = "Unknown message type %s" % msg_type
+ else:
+ ex_msg = "Unknown message with no type"
+ raise MessageProcessingError(ex_msg)
# build message with its attributes
self._draft = ctor()
self._draft.selfbuild(attributes)
@@ -242,7 +246,8 @@ def ev_read(self, worker, node, sname, msg):
self._close()
return
except MessageProcessingError as ex:
- self.logger.error("MessageProcessingError: %s", ex)
+ self.logger.error("MessageProcessingError: %s (initiator=%s)",
+ ex, self.initiator)
if self.initiator:
self.recv(StdErrMessage(node, str(ex)))
else:
diff --git a/tests/TreeGatewayTest.py b/tests/TreeGatewayTest.py
index ef97846b..d5098d2a 100644
--- a/tests/TreeGatewayTest.py
+++ b/tests/TreeGatewayTest.py
@@ -256,13 +256,18 @@ def test_channel_err_unknown_tag_setup(self):
def test_err_unknown_msg(self):
"""test gateway unknown message"""
self._check_channel_err('',
- 'Unknown message type',
+ 'Unknown message type ABC',
openchan=False)
def test_channel_err_unknown_msg(self):
"""test gateway channel unknown message"""
self._check_channel_err('',
- 'Unknown message type')
+ 'Unknown message type ABC')
+
+ def test_channel_err_no_type_msg(self):
+ """test gateway channel message with no type"""
+ self._check_channel_err('',
+ 'Unknown message with no type')
def test_err_xml_malformed(self):
"""test gateway malformed xml message"""