{"record":{"id":"2a9e9c2fea371ee0","repo":"wtfutil/wtf","slug":"error-fetching-task-s","errorCode":null,"errorMessage":"error fetching task: %s","messagePattern":"error fetching task: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/asana/client.go","lineNumber":119,"sourceCode":"\t\treturn nil, fmt.Errorf(\"error fetching tasks: %s\", err)\n\t}\n\n\tprocessFetchedTasks(client, &fetchedTasks, &taskItems, &uidToName, mode, workspaceId, uid)\n\n\treturn taskItems, nil\n\n}\n\nfunc toggleTaskCompletionById(token, taskId string) error {\n\tclient := asana.NewClientWithAccessToken(token)\n\n\tt := &asana.Task{\n\t\tID: taskId,\n\t}\n\n\terr := t.Fetch(client)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error fetching task: %s\", err)\n\t}\n\n\tupdateReq := &asana.UpdateTaskRequest{}\n\n\tif *t.Completed {\n\t\tf := false\n\t\tupdateReq.Completed = &f\n\t} else {\n\t\tt := true\n\t\tupdateReq.Completed = &t\n\t}\n\n\terr = t.Update(client, updateReq)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error updating task: %s\", err)\n\t}\n\n\treturn nil","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/modules/asana/client.go#L101-L137","documentation":"Returned by toggleTaskCompletionById when asana.Task.Fetch fails to retrieve the task before toggling its completed flag. The library must fetch the task first to read its current Completed status; if that read fails (bad task ID, permissions, network), this error is produced. The toggle is not performed.","triggerScenarios":"Calling toggleTaskCompletion with a task GID that does not exist or is inaccessible: task deleted or moved to another project the token can't see, typo'd GID, invalid/expired token, or network failure during t.Fetch(client).","commonSituations":"Stale task ID cached from a previous sync after the task was deleted in Asana; token lost access to the task's workspace; offline/VPN issues; GID copied incorrectly (Asana GIDs are long numeric strings).","solutions":["Verify the task GID exists: curl -H 'Authorization: Bearer <token>' https://app.asana.com/api/1.0/tasks/<gid>.","Confirm the token has read access to the workspace/project containing the task.","Refresh any cached task IDs — the task may have been deleted or permanently completed.","Retry if the wrapped error indicates a transient network or 5xx condition."],"exampleFix":"// before\nerr := t.Fetch(client)\nif err != nil {\n    return fmt.Errorf(\"error fetching task: %s\", err)\n}\n// after\nerr := t.Fetch(client)\nif err != nil {\n    return fmt.Errorf(\"error fetching task %s before toggle: %w\", taskId, err)\n}","handlingStrategy":"validation","validationCode":"func taskExists(client *asana.Client, taskId string) error {\n    if taskId == \"\" {\n        return fmt.Errorf(\"empty task id\")\n    }\n    t := &asana.Task{ID: taskId}\n    if err := t.Fetch(client); err != nil {\n        return fmt.Errorf(\"task %s not accessible: %w\", taskId, err)\n    }\n    return nil\n}","typeGuard":"func validTaskID(id string) bool {\n    if id == \"\" { return false }\n    for _, r := range id {\n        if r < '0' || r > '9' { return false }\n    }\n    return true\n}","tryCatchPattern":"err := mod.Toggle(taskId)\nif err != nil {\n    if strings.Contains(err.Error(), \"error fetching task\") {\n        log.Printf(\"task %s missing or inaccessible, refreshing ID cache\", taskId)\n        return refreshAndRetry(taskId)\n    }\n    return err\n}","preventionTips":["Refresh cached task GIDs regularly; deleted tasks fail on fetch.","Verify the token can read the task's workspace before toggling.","Validate the GID format (numeric string) before calling.","Handle wrapped network errors with a retry rather than treating the task as gone."],"tags":["asana","api","task","fetch","error-wrapping"],"backgroundTag":"asana-task-not-found","analyzedSha":"bb838c1ccb0f0f3223690df44afdec663d622881","analyzedAt":"2026-09-03T17:02:45.030Z","contentChangedAt":"2026-09-03T17:02:45.030Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}