{"record":{"id":"568b1e899758005a","repo":"juanfont/headscale","slug":"listing-containers-w","errorCode":null,"errorMessage":"listing containers: %w","messagePattern":"listing containers: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/hi/cleanup.go","lineNumber":68,"sourceCode":"\t\t}\n\t}\n\n\treturn nil\n}\n\n// killTestContainers terminates and removes all test containers.\nfunc killTestContainers(ctx context.Context) error {\n\tcli, err := createDockerClient(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating Docker client: %w\", err)\n\t}\n\tdefer cli.Close()\n\n\tcontainers, err := cli.ContainerList(ctx, container.ListOptions{\n\t\tAll: true,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"listing containers: %w\", err)\n\t}\n\n\tremoved := 0\n\n\tfor _, cont := range containers {\n\t\tif isTestContainerName(cont.Names) {\n\t\t\tif killAndRemove(ctx, cli, cont) {\n\t\t\t\tremoved++\n\t\t\t}\n\t\t}\n\t}\n\n\tif removed > 0 {\n\t\tfmt.Printf(\"Removed %d test containers\\n\", removed)\n\t} else {\n\t\tfmt.Println(\"No test containers found to remove\")\n\t}\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/hi/cleanup.go#L50-L86","documentation":"Returned by killTestContainers when cli.ContainerList(All:true) fails while enumerating every container to find test ones. The Docker API call can fail due to daemon connectivity loss, insufficient permissions, or an API-version mismatch between the client library and the daemon.","triggerScenarios":"Running `hi kill` when the daemon restarts mid-call; the negotiated API version being newer than the daemon supports (very old engine); permission denied on the socket; remote daemon dropping the connection.","commonSituations":"Docker being upgraded while the command runs; pinned DOCKER_API_VERSION env var set to an unsupported value; flaky remote daemon over TLS; CI runners recycling the daemon.","solutions":["Retry after confirming `docker ps -a` works","Unset DOCKER_API_VERSION if it was pinned for another tool","Upgrade Docker Engine if it is far older than the client library expects","Check the wrapped message for the exact API error"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"Retry ContainerList once on transient errors; abort with the wrapped message if `docker ps -a` also fails manually.","preventionTips":["Do not pin DOCKER_API_VERSION unless the daemon definitely supports it","Keep Docker Engine reasonably current relative to the go docker client library","Avoid restarting the daemon while hi commands run"],"tags":["docker","container-list","api","hi"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}