arikawa icon indicating copy to clipboard operation
arikawa copied to clipboard

v4: Error notifying library and halting

Open diamondburned opened this issue 4 years ago • 2 comments

For v3, we should add a library that allows the library users to intercept internal errors (especially ones that are automatically handled). This will allow the user to intercept and halt instances that might try to recover itself from unrecoverable situations, such as when a token is invalidated.

The basic API of this library is listed below:

type NotifiedFunc func(err error) (ok bool)

type Notifier interface {
    Notify(err error) (ok bool)
    AddNotifiedFunc(fn NotifiedFunc)
}

In this API, the NotifiedFunc function will be called on every internal error. If the function returns false in the chain, then the whole operation must be stopped and cleaned up. This is because by returning false, the user is suggesting that the error indicates an unrecoverable state.

Ideally, the library can handle this internally, but adding handlers for every single edge case is not completely feasible, so flexibility should be preferred.


As a sidenote, the API would be a lot more reasonable if Open() is blocking, since it would allow the user to handle unexpected cases without needing to rely on weird callbacks that are potentially racy; I can make a separate issue for this if there's not a good use case for a non-blocking Open().

diamondburned avatar Jun 10 '21 19:06 diamondburned

Ideally, this should completely replace all ErrorLog{,ger} fields and the wsutil.WSError global variable.

diamondburned avatar Jun 12 '21 21:06 diamondburned

Moved to v4.

diamondburned avatar Oct 13 '22 22:10 diamondburned