nikoksr/notify

refactor(send): Add MustSend method

nikoksr opened this issue · 1 comments

Is your feature request related to a problem? Please describe.

As discussed here the error handling in notify.Send might not fit everybodys needs. There might be occasions where you want Notify to immediately stop sending the message to the other receivers in case the preceding receiver was not reachable. Maybe its a very crucial message and you need to make sure that it was send to all receivers successfully. On the other hand there might be occasions where you don't care if Notify might not be able to reach some of the receivers and you just want it to continue after not reaching a receiver.

Describe the solution you'd like

In addition to the current notify.Send method we will add the notify.MustSend method. notify.Send will keep its current behavior which is to keep sending messages even after an error occured but.. it will need to collate all errors into one (something like #22). Instead of joining these errors I'm rather thinking about adding a custom error type which holds an array of unreachable receivers. notify.MustSend on the other will return the first error right after it occurs, basically skipping all remaining receivers.

Example for new error:

type ErrSendToReceivers struct {
    Receivers []string
    Err            error
}

I started working on this issues and realized there was a problem with our idea.

For services like notify.Discord, our idea works well. You can either return a potential error immediately (MustSend behavior) or collect it in an error array (Send behavior) if a single receiver fails. But services like notify.AmazonSES manage the receiver list by itself, so we can't control the behavior whether the service should ignore single failed receivers or not. This would lead to some services supporting our intended behavior and some not.

The behavior should be predictable and not different from service to service. Closing this for now, discussion may keep going.