Skip to content

Errors

Execute() returns your function’s result and error untouched, except when the breaker refuses to run it:

ErrorReturned when
fluxgo.ErrOpenStateThe circuit is Open and the request is rejected immediately
fluxgo.ErrTooManyRequestsThe circuit is Half-Open and the HalfOpenMaxRequests probe quota is already used

Both are the same sentinels as in gobreaker, and are meant to be tested with errors.Is.

res, err := cb.Execute(func() (interface{}, error) {
return callDownstream()
})
switch {
case errors.Is(err, fluxgo.ErrOpenState):
return fallback() // fast reject, the downstream was not called
case errors.Is(err, fluxgo.ErrTooManyRequests):
return fallback() // a probe is already in flight
case err != nil:
return nil, err // the downstream's own error
}

An Open circuit rejects in about 57 ns with zero allocations, so keeping a failing dependency behind the breaker is cheap. See Performance.

A request classified as degraded counts as a failure internally only. Your caller still receives the original result and error.