[GH-ISSUE #340] [BUG] GetTaskInfo doesn't return expected errors #150

Closed
opened 2026-03-02 05:19:09 +03:00 by kerem · 2 comments
Owner

Originally created by @jonnyguio on GitHub (Nov 9, 2021).
Original GitHub issue: https://github.com/hibiken/asynq/issues/340

Originally assigned to: @hibiken on GitHub.

Describe the bug
The method GetTaskInfo of the Inspector doesn't return the expected error: it creates a new error appending the two possible errors to the string asynq: .

To Reproduce

i := asynq.NewInspector(asynq.RedisClientOpt{Addr: "127.0.0.1:6379"})
t, err := i.GetTaskInfo("default", "non existent id")
fmt.Println(err == asynq.ErrTaskNotFound) // false

Expected behavior

i := asynq.NewInspector(asynq.RedisClientOpt{Addr: "127.0.0.1:6379"})
t, err := i.GetTaskInfo("default", "non existent id")
fmt.Println(err == asynq.ErrTaskNotFound) // true

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: any
  • v0.18.6

Additional context
The documentation states:

GetTaskInfo retrieves task information given a task id and queue name.

Returns ErrQueueNotFound if a queue with the given name doesn't exist. Returns ErrTaskNotFound if a task with the given id doesn't exist in the queue. 

I believe that returning a new error, even if it can be helpful to know that the context of the error was from asynq, it's misleading from the actual implementation and makes handling of an expected scenario not as good as straight comparisson between errors.

Originally created by @jonnyguio on GitHub (Nov 9, 2021). Original GitHub issue: https://github.com/hibiken/asynq/issues/340 Originally assigned to: @hibiken on GitHub. **Describe the bug** The method `GetTaskInfo` of the `Inspector` doesn't return the expected error: it creates a new error appending the two possible errors to the string `asynq: `. **To Reproduce** ``` i := asynq.NewInspector(asynq.RedisClientOpt{Addr: "127.0.0.1:6379"}) t, err := i.GetTaskInfo("default", "non existent id") fmt.Println(err == asynq.ErrTaskNotFound) // false ``` **Expected behavior** ``` i := asynq.NewInspector(asynq.RedisClientOpt{Addr: "127.0.0.1:6379"}) t, err := i.GetTaskInfo("default", "non existent id") fmt.Println(err == asynq.ErrTaskNotFound) // true ``` **Screenshots** If applicable, add screenshots to help explain your problem. **Environment (please complete the following information):** - OS: any - v0.18.6 **Additional context** The documentation states: ``` GetTaskInfo retrieves task information given a task id and queue name. Returns ErrQueueNotFound if a queue with the given name doesn't exist. Returns ErrTaskNotFound if a task with the given id doesn't exist in the queue. ``` I believe that returning a new error, even if it can be helpful to know that the context of the error was from `asynq`, it's misleading from the actual implementation and makes handling of an expected scenario not as good as straight comparisson between errors.
kerem 2026-03-02 05:19:09 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@hibiken commented on GitHub (Nov 9, 2021):

@jonnyguio Thank you for opening an issue!
I believe this is a documentation bug, Inspector is returning an error that wraps those sentinel error values (to allow for flexibility in adding more context in the error in the future if needed).

So instead of directly comparing to the error value, the user of the package needs to unwrap it:

if errors.Is(err, asynq.ErrTaskNotFound) {
     // handle error
}

This pattern was taken from this blog: https://go.dev/blog/go1.13-errors

Thanks again for spotting this, I'll update the godoc 👍

<!-- gh-comment-id:964355280 --> @hibiken commented on GitHub (Nov 9, 2021): @jonnyguio Thank you for opening an issue! I believe this is a documentation bug, Inspector is returning an error that wraps those sentinel error values (to allow for flexibility in adding more context in the error in the future if needed). So instead of directly comparing to the error value, the user of the package needs to unwrap it: ```go if errors.Is(err, asynq.ErrTaskNotFound) { // handle error } ``` This pattern was taken from this blog: https://go.dev/blog/go1.13-errors Thanks again for spotting this, I'll update the godoc 👍
Author
Owner

@jonnyguio commented on GitHub (Nov 9, 2021):

Oh, that's great! That makes a lot of sense, I missed this way of handling it.

Keep it up with the good work! 😄

<!-- gh-comment-id:964519820 --> @jonnyguio commented on GitHub (Nov 9, 2021): Oh, that's great! That makes a lot of sense, I missed this way of handling it. Keep it up with the good work! :smile:
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#150
No description provided.