mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-26 07:42:17 +08:00
Adjust error message, use TrimSpace for more robust empty typename check
This commit is contained in:
parent
4bce28d677
commit
6817af366a
@ -6,6 +6,7 @@ package asynq
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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.
|
// ErrDuplicateTask error only applies to tasks enqueued with a Unique option.
|
||||||
var ErrDuplicateTask = errors.New("task already exists")
|
var ErrDuplicateTask = errors.New("task already exists")
|
||||||
|
|
||||||
// ErrEmptyTypeTask indicates that task's typename is not specified.
|
// ErrEmptyTypename indicates that task's typename is empty.
|
||||||
var ErrEmptyTypeTask = errors.New("task typename not specified")
|
var ErrEmptyTypename = errors.New("task typename cannot be empty")
|
||||||
|
|
||||||
type option struct {
|
type option struct {
|
||||||
retry int
|
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.
|
// If no ProcessAt or ProcessIn options are provided, the task will be pending immediately.
|
||||||
func (c *Client) Enqueue(task *Task, opts ...Option) (*TaskInfo, error) {
|
func (c *Client) Enqueue(task *Task, opts ...Option) (*TaskInfo, error) {
|
||||||
if task.Type() == "" {
|
if strings.TrimSpace(task.Type()) == "" {
|
||||||
return nil, fmt.Errorf("%w", ErrEmptyTypeTask)
|
return nil, fmt.Errorf("%w", ErrEmptyTypename)
|
||||||
}
|
}
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
if defaults, ok := c.opts[task.Type()]; ok {
|
if defaults, ok := c.opts[task.Type()]; ok {
|
||||||
|
@ -98,7 +98,7 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
|
|||||||
mux.mu.Lock()
|
mux.mu.Lock()
|
||||||
defer mux.mu.Unlock()
|
defer mux.mu.Unlock()
|
||||||
|
|
||||||
if pattern == "" {
|
if strings.TrimSpace(pattern) == "" {
|
||||||
panic("asynq: invalid pattern")
|
panic("asynq: invalid pattern")
|
||||||
}
|
}
|
||||||
if handler == nil {
|
if handler == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user