Forum OpenACS Development: Problem in incoming email reply handling

The notifications package sweeps incoming email replies to a notification.

The code looks like this

    # Loop through and transactionally process each one
    foreach reply $replies {
        set reply_id [lindex $reply 0]
        set type_id [lindex $reply 1]

        ns_log Debug "process_all_replies: one reply $reply_id of type $type_id"

        if { [ catch {
            notification::type::process_reply -type_id $type_id -reply_id $reply_id
	    db_dml deletehold {}
            notification::reply::delete -reply_id $reply_id
        } err ] } {
            ns_log Error "notification::reply::sweep::process_all_replies: bombed on reply_id $reply_id:\n$err"
        }
    }
If there is an error processing a reply, it is never removed from the queue as the delete is inside the catch. What's the best way to fix this? It will cause the erroring reply to hold up all incoming email. In my case the error was in forums::message::new after notifications, so my system kept processing the rely and sending out a notification for it. Not a good situation. I moved the delete outside the catch so a reply is only processed once.
Collapse
Posted by Tom Jackson on

If the delete causes an error, you have the same effect: on next cycle, the delete will cause an error outside of catch and the rest of the replies will go unprocessed. The problem is you don't know which of the three statements in the catch will cause the error. The bug is putting too much in one catch so that you have no easy way to figure out how to respond to the error.

One idea is to do each statement in an if catch, deciding what to do if you get an error. Undo the damage, log the error, and use [continue] to keep on going, skipping the remaining statements in the loop:

 if {[catch {
      notification::type::process_reply -type_id $type_id -reply_id $reply_id
 } err]} {
      carefully_undo_process_reply_error
      log Error "process_reply failed..."
      continue
 } 
 ...
Collapse
Posted by Malte Sussdorff on
Whatever idea we come up with should be implemented in the incoming_email of acs-mail-lite and we might think (if there is time) to make notifications a callback implementation for acs-mail-lite, avoiding two systems at the same time to do the e-mail sweeping.