diff --git a/servemux.go b/servemux.go index 411dcf8..26bbf44 100644 --- a/servemux.go +++ b/servemux.go @@ -6,12 +6,16 @@ package asynq import ( "context" + "errors" "fmt" "sort" "strings" "sync" ) +// ErrHandlerNotFound indicates that no task handler was found for a given pattern. +var ErrHandlerNotFound = errors.New("handler not found for task") + // ServeMux is a multiplexer for asynchronous tasks. // It matches the type of each task against a list of registered patterns // and calls the handler for the pattern that most closely matches the @@ -149,7 +153,7 @@ func (mux *ServeMux) Use(mws ...MiddlewareFunc) { // NotFound returns an error indicating that the handler was not found for the given task. func NotFound(ctx context.Context, task *Task) error { - return fmt.Errorf("handler not found for task %q", task.Type()) + return fmt.Errorf("%w %q", ErrHandlerNotFound, task.Type()) } // NotFoundHandler returns a simple task handler that returns a ``not found`` error.