From: W. Trevor King Date: Sun, 2 Sep 2012 12:32:46 +0000 (-0400) Subject: mailpipe: fix InvalidHandlerMessage error message construction. X-Git-Tag: v0.3~35 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=18b5afe3df372c21d7e67a3fc31c20655ce7aa4c;p=pygrader.git 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. --- 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):