[Mailman-Users] Writing a custom handler

Mark Sapiro mark at msapiro.net
Tue Jul 2 23:37:22 CEST 2013

On 07/02/2013 01:49 PM, Chris Nulk wrote:
> On 7/2/2013 12:17 PM, Mark Sapiro wrote:
>> On 07/02/2013 11:38 AM, Chris Nulk wrote:

>>>      except:
>>>          # unspecified error
>>>          # log it and continue with the next pipeline handler
>>>          syslog('error',
>>>                 'ERROR: %s: %s' % (sys.exc_info()[0], sys.exc_info()[1])
>>>                )
>>>          return False
>> Do you really want to do this? The Mailman philosophy is all caught and
>> handled exceptions should be explicit. An unanticipated exception will
>> be caught at the top qrunner level which will log the error with
>> traceback in the 'error' log and shunt the message rather than
>> continuing processing with a message that triggered an unanticipated
>> exception.
> Instead of returning, should I raise an exception?  For the IOError or
> any error, whether or not the file can be read or perform a stat isn't a
> big deal.  I would rather log the error, clear the exception and keep
> going.  If there is a problem in this function, returning False just
> means the ban_file hasn't changed so I will still be running sender
> addresses against a potentially older banlist.

If you raise some exception other than the Mailman.Errors exceptions
DiscardMessage, HoldMessage or RejectMessage, it will be the same as if
you didn't catch the exception, i.e., the exception will be logged in
the 'error' log with a traceback and the message will be shunted.

I can see that you don't really want that because if your ban file is
unreadable or you can't stat it for some reason, you'd be shunting every
message for a reason that has really nothing to do with processing the
message. So, I think you do want to catch the exception, log it and
return as that is the only way to continue processing messages.

Just watch your 'error' log as you'll get an entry per message if
something is wrong.

Mark Sapiro <mark at msapiro.net>        The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan

More information about the Mailman-Users mailing list