Skip to main content
Version: 0.2

Errors

Sentinel errors​

ErrorReturned byMeaning
ErrPoolClosedevery submit, and waiters on dropped jobsthe pool is closed or closing
ErrPoolFullTrySubmit, TrySubmitJob, RateLimiter.TrySubmitthe queue is full
ErrInvalidConfigNewPoolan option is out of range; wrapped with details
ErrJobPanicjobs that panickedmatched by every *PanicError
ErrRateLimitedRateLimiter.TrySubmitno token is available
ErrLimiterStoppedRateLimiter.Submit, RateLimiter.TrySubmitthe rate limiter was stopped

Match them with errors.Is:

switch err := pool.TrySubmit(job); {
case err == nil:
case errors.Is(err, worker.ErrPoolFull):
return errBusy
case errors.Is(err, worker.ErrPoolClosed):
return errShuttingDown
}

Errors from jobs​

A job's own error is returned unchanged by SubmitWait, futures, and groups — after all retries — so match it as you normally would. Two wrappers can appear around it:

TypeCreated byNotes
*PanicErrorthe pool, when a job panicsmatches ErrJobPanic; Value and Stack hold the panic; unwraps to Value if it is an error
permanent errorworker.Permanent(err)stops retries; transparent to errors.Is and errors.As
if perr, ok := errors.AsType[*worker.PanicError](err); ok {
log.Printf("panic: %v\n%s", perr.Value, perr.Stack)
}

Context errors​

Waiting operations return ctx.Err() — context.Canceled or context.DeadlineExceeded — when their context ends first:

  • SubmitContext, SubmitWait, SubmitJobWait, RateLimiter.Submit, and Future.Await, when the caller's context ends,
  • a job's result, when its attempt timed out on the last attempt, or its context was cancelled by the caller, a group, or a forced close. If the job returned its own error, the result matches that error too.

Panics from constructors​

NewTicker and NewRateLimiter panic on a non-positive interval or count, since those are programming errors. NewPool returns ErrInvalidConfig instead, because pool sizes often come from configuration.