2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-11-10 03:21:55 +08:00

Adjust error message, use TrimSpace for more robust empty typename check

This commit is contained in:
Luqqk 2021-08-02 01:23:58 +02:00 committed by Ken Hibino
parent 4bce28d677
commit 6817af366a
2 changed files with 6 additions and 5 deletions

View File

@ -6,6 +6,7 @@ package asynq
import (
"fmt"
"strings"
"sync"
"time"
@ -178,8 +179,8 @@ func (d processInOption) Value() interface{} { return time.Duration(d) }
// ErrDuplicateTask error only applies to tasks enqueued with a Unique option.
var ErrDuplicateTask = errors.New("task already exists")
// ErrEmptyTypeTask indicates that task's typename is not specified.
var ErrEmptyTypeTask = errors.New("task typename not specified")
// ErrEmptyTypename indicates that task's typename is empty.
var ErrEmptyTypename = errors.New("task typename cannot be empty")
type option struct {
retry int
@ -269,8 +270,8 @@ func (c *Client) Close() error {
//
// If no ProcessAt or ProcessIn options are provided, the task will be pending immediately.
func (c *Client) Enqueue(task *Task, opts ...Option) (*TaskInfo, error) {
if task.Type() == "" {
return nil, fmt.Errorf("%w", ErrEmptyTypeTask)
if strings.TrimSpace(task.Type()) == "" {
return nil, fmt.Errorf("%w", ErrEmptyTypename)
}
c.mu.Lock()
if defaults, ok := c.opts[task.Type()]; ok {

View File

@ -98,7 +98,7 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
mux.mu.Lock()
defer mux.mu.Unlock()
if pattern == "" {
if strings.TrimSpace(pattern) == "" {
panic("asynq: invalid pattern")
}
if handler == nil {