Skip to content

Tree: improve handling of MessageProcessingError #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/ClusterShell/Communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions tests/TreeGatewayTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<message msgid="24" type="ABC"></message>',
'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('<message msgid="24" type="ABC"></message>',
'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('<message msgid="24"></message>',
'Unknown message with no type')

def test_err_xml_malformed(self):
"""test gateway malformed xml message"""
Expand Down
Loading