From a4a7c2691f16e53f276efdf52d9fa88092cd6353 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 2 Sep 2012 08:35:50 -0400 Subject: [PATCH] mailpipe: flesh out InvalidMessage attributes before raising exceptions. This tacks on all the interesting attribute data which the function that originally raised the exception may not have known about. We want this metadata in all cases, not just those where we are constructing a response message. --- pygrader/mailpipe.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pygrader/mailpipe.py b/pygrader/mailpipe.py index 92215c6..6a42eae 100644 --- a/pygrader/mailpipe.py +++ b/pygrader/mailpipe.py @@ -562,17 +562,18 @@ def mailpipe(basedir, course, stream=None, mailbox=None, input_=None, person=person, subject=subject, max_late=max_late, dry_run=dry_run) except _InvalidMessage as error: + error.course = course + error.message = original + if person is not None and not hasattr(error, 'person'): + error.person = person + if subject is not None and not hasattr(error, 'subject'): + error.subject = subject + if target is not None and not hasattr(error, 'target'): + error.target = target + _LOG.warn('invalid message {}'.format(error.message_id())) if not continue_after_invalid_message: raise if respond: - error.course = course - error.message = original - if person is not None and not hasattr(error, 'person'): - error.person = person - if subject is not None and not hasattr(error, 'subject'): - error.subject = subject - if target is not None and not hasattr(error, 'target'): - error.target = target response = _get_error_response(error) respond(response) except _Response as response: @@ -629,6 +630,8 @@ def _load_messages(course, stream, mailbox=None, input_=None, output=None, try: ret = _parse_message(course=course, message=msg) except _InvalidMessage as error: + error.message = msg + _LOG.warn('invalid message {}'.format(error.message_id())) if not continue_after_invalid_message: raise if respond: -- 2.26.2