{"record":{"id":"5bb4bbc6f686be1e","repo":"docker/cli","slug":"failed-to-get-tasks-w","errorCode":null,"errorMessage":"failed to get tasks: %w","messagePattern":"failed to get tasks: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/stack/remove.go","lineNumber":179,"sourceCode":"\tswarm.TaskStateReady:     7,\n\tswarm.TaskStateStarting:  8,\n\tswarm.TaskStateRunning:   9,\n\tswarm.TaskStateComplete:  10,\n\tswarm.TaskStateShutdown:  11,\n\tswarm.TaskStateFailed:    12,\n\tswarm.TaskStateRejected:  13,\n}\n\nfunc terminalState(state swarm.TaskState) bool {\n\treturn numberedStates[state] > numberedStates[swarm.TaskStateRunning]\n}\n\nfunc waitOnTasks(ctx context.Context, apiClient client.APIClient, namespace string) error {\n\tterminalStatesReached := 0\n\tfor {\n\t\tres, err := getStackTasks(ctx, apiClient, namespace)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to get tasks: %w\", err)\n\t\t}\n\n\t\tfor _, task := range res.Items {\n\t\t\tif terminalState(task.Status.State) {\n\t\t\t\tterminalStatesReached++\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif terminalStatesReached == len(res.Items) {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":161,"sourceCodeEnd":195,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/stack/remove.go#L161-L195","documentation":"Thrown by waitOnTasks while polling swarm tasks during 'docker stack rm'. The loop calls getStackTasks(ctx, apiClient, namespace) and wraps any non-nil error from the daemon task-list API. It surfaces transport, auth, or swarm-state failures encountered while waiting for a stack's tasks to reach a terminal state.","triggerScenarios":"Running 'docker stack rm <stack>' against a manager that cannot list tasks (network drop, node lost quorum, task-list API error, or the swarm was partially torn down while waiting). Any failure inside getStackTasks propagates as 'failed to get tasks: <underlying>'.","commonSituations":"Manager left the swarm or lost quorum mid-removal; DOCKER_HOST points at an unhealthy daemon; TLS/MTLS misconfiguration between CLI and manager; large stacks where the wait loop races the daemon shutting down services.","solutions":["Check 'docker node ls' and 'docker info' to confirm the targeted manager is reachable and healthy.","Re-run 'docker stack rm <stack>' once the swarm recovers quorum / the daemon is back up.","If the wait loop itself is the problem, verify DOCKER_HOST / context and daemon connectivity with 'docker version'.","Inspect underlying cause by running with DOCKER_DEBUG=1 / 'docker --debug stack rm' to see the wrapped error."],"exampleFix":"// before: removal may hang/fail if the manager is temporarily unreachable\ndocker stack rm mystack\n\n// after: target a known-good manager and confirm quorum first\ndocker node ls\ndocker context use manager-prod\ndocker stack rm mystack","handlingStrategy":"try-catch","validationCode":"// Before stacking removal, confirm manager reachability\nif err := pingManager(ctx, apiClient); err != nil {\n    return fmt.Errorf(\"swarm manager unreachable before stack rm: %w\", err)\n}","typeGuard":"func isTaskListErr(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"failed to get tasks:\")\n}","tryCatchPattern":"err := waitOnTasks(ctx, client, ns)\nif err != nil {\n    // non-fatal: stack may still be removed; retry or surface to user\n    return fmt.Errorf(\"stack removal polling failed: %w\", err)\n}","preventionTips":["Confirm 'docker node ls' shows a reachable manager before issuing stack rm.","Script stack rm to be idempotent and retry on transient task-list failures.","Use 'docker --debug stack rm' to capture the wrapped underlying error."],"tags":["swarm","stack","task","daemon","network"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}