From 18b5afe3df372c21d7e67a3fc31c20655ce7aa4c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 2 Sep 2012 08:32:46 -0400 Subject: [PATCH] mailpipe: fix InvalidHandlerMessage error message construction. `target` is an explicit argument, not in `**kwargs`. I also removed the InvalidHandlerMessage error logging, because we're raising an exception. The calling function can log the exception if it catches it. If it doesn't, the user will see the message in the traceback. --- pygrader/mailpipe.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pygrader/mailpipe.py b/pygrader/mailpipe.py index 609ca94..92215c6 100644 --- a/pygrader/mailpipe.py +++ b/pygrader/mailpipe.py @@ -80,8 +80,7 @@ class SubjectlessMessage (_InvalidSubjectMessage): class InvalidHandlerMessage (_InvalidSubjectMessage): def __init__(self, target=None, handlers=None, **kwargs): if 'error' not in kwargs: - kwargs['error'] = 'no handler for {!r}'.format( - kwargs.get('target', None)) + kwargs['error'] = 'no handler for {!r}'.format(target) super(InvalidHandlerMessage, self).__init__(**kwargs) self.target = target self.handlers = handlers @@ -755,10 +754,9 @@ def _get_message_target(subject): def _get_handler(handlers, target): try: handler = handlers[target] - except KeyError: - response_subject = 'no handler for {}'.format(target) - _LOG.warning(_color_string(string=response_subject)) - raise InvalidHandlerMessage(target=target, handlers=handlers) + except KeyError as error: + raise InvalidHandlerMessage( + target=target, handlers=handlers) from error return handler def _get_verified_message(message, pgp_key): -- 2.26.2