{"record":{"id":"23c5cb76668de6dc","repo":"hibiken/asynq","slug":"task-cannot-be-nil","errorCode":null,"errorMessage":"task cannot be nil","messagePattern":"task cannot be nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client.go","lineNumber":387,"sourceCode":"func (c *Client) Enqueue(task *Task, opts ...Option) (*TaskInfo, error) {\n\treturn c.EnqueueContext(context.Background(), task, opts...)\n}\n\n// EnqueueContext enqueues the given task to a queue.\n//\n// EnqueueContext returns TaskInfo and nil error if the task is enqueued successfully, otherwise returns a non-nil error.\n//\n// The argument opts specifies the behavior of task processing.\n// If there are conflicting Option values the last one overrides others.\n// Any options provided to NewTask can be overridden by options passed to Enqueue.\n// By default, max retry is set to 25 and timeout is set to 30 minutes.\n//\n// If no ProcessAt or ProcessIn options are provided, the task will be pending immediately.\n//\n// The first argument context applies to the enqueue operation. To specify task timeout and deadline, use Timeout and Deadline option instead.\nfunc (c *Client) EnqueueContext(ctx context.Context, task *Task, opts ...Option) (*TaskInfo, error) {\n\tif task == nil {\n\t\treturn nil, fmt.Errorf(\"task cannot be nil\")\n\t}\n\tif strings.TrimSpace(task.Type()) == \"\" {\n\t\treturn nil, fmt.Errorf(\"task typename cannot be empty\")\n\t}\n\t// merge task options with the options provided at enqueue time.\n\topts = append(task.opts, opts...)\n\topt, err := composeOptions(opts...)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdeadline := noDeadline\n\tif !opt.deadline.IsZero() {\n\t\tdeadline = opt.deadline\n\t}\n\ttimeout := noTimeout\n\tif opt.timeout != 0 {\n\t\ttimeout = opt.timeout\n\t}","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/hibiken/asynq/blob/d135f1439bee74e989b7f9b41ecd542cc87f024a/client.go#L369-L405","documentation":"A generic validation guard in EnqueueContext: it fires when the caller passes a nil *Task pointer to enqueue, meaning there is no task payload or typename to serialize into redis, so enqueueing cannot proceed.","triggerScenarios":"Thrown at client.go:387 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a task created via asynq.NewTask(typename, payload) instead of nil","Check for nil before calling Enqueue/EnqueueContext when the task comes from an optional or fallible code path"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d135f1439bee74e989b7f9b41ecd542cc87f024a","analyzedAt":"2026-09-07T19:02:34.660Z","contentChangedAt":"2026-09-07T19:02:34.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}