{"record":{"id":"c471a39491676b8c","repo":"wtfutil/wtf","slug":"could-not-get-container-list-w","errorCode":null,"errorMessage":"could not get container list: %w","messagePattern":"could not get container list: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/docker/client.go","lineNumber":113,"sourceCode":"\n\tpadSlice(true, sysInfo, func(i int) string {\n\t\treturn sysInfo[i].name\n\t}, func(i int, newVal string) {\n\t\tsysInfo[i].name = newVal\n\t})\n\n\tresult := \"\"\n\tfor _, info := range sysInfo {\n\t\tresult += fmt.Sprintf(\"[%s]%s %s\\n\", widget.settings.labelColor, info.name, info.value)\n\t}\n\n\treturn result\n}\n\nfunc (widget *Widget) getContainerStates() string {\n\tcntrs, err := widget.cli.ContainerList(context.Background(), container.ListOptions{All: true})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not get container list: %w\", err).Error()\n\t}\n\n\tif len(cntrs) == 0 {\n\t\treturn \" no containers\"\n\t}\n\n\tcolorMap := map[string]string{\n\t\t\"created\":    \"green\",\n\t\t\"running\":    \"lime\",\n\t\t\"paused\":     \"yellow\",\n\t\t\"restarting\": \"yellow\",\n\t\t\"removing\":   \"yellow\",\n\t\t\"exited\":     \"red\",\n\t\t\"dead\":       \"red\",\n\t}\n\n\tcontainers := []struct {\n\t\tname  string","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/modules/docker/client.go#L95-L131","documentation":"getContainerStates calls cli.ContainerList(ctx, container.ListOptions{All: true}); any transport or API failure is stringified as \"could not get container list\" into the widget buffer. The daemon's /containers/json call did not return a usable list.","triggerScenarios":"cli.ContainerList fails: daemon unreachable (same causes as Info), permission denied on the socket, stale connection after daemon restart, or an invalid All option on a mismatched API version.","commonSituations":"Docker Desktop sleeping/suspending on laptops, socket permissions after a fresh install, remote daemon behind an SSH tunnel that dropped, API version skew after a Docker upgrade.","solutions":["Confirm docker ps -a works in the same environment.","Recreate the Docker client (NewClientWithOpts) if the daemon restarted — cached connections can go stale.","Fix socket permissions / docker group membership.","Align client library and daemon versions if the error persists across calls."],"exampleFix":"// before\ncntrs, err := widget.cli.ContainerList(context.Background(), container.ListOptions{All: true})\nif err != nil {\n\treturn fmt.Errorf(\"could not get container list: %w\", err).Error()\n}\n// after\ncntrs, err := widget.cli.ContainerList(context.Background(), container.ListOptions{All: true})\nif err != nil {\n\treturn fmt.Errorf(\"could not get container list: %w\", err).Error() // consider rebuilding cli on connection errors\n}","handlingStrategy":"fallback","validationCode":"if _, err := widget.cli.Ping(context.Background()); err != nil {\n\t// daemon unreachable — skip ContainerList and show connectivity hint\n}","typeGuard":"func isConnectionReset(err error) bool {\n\treturn errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET) || errors.Is(err, context.DeadlineExceeded)\n}","tryCatchPattern":"cntrs, err := widget.cli.ContainerList(ctx, container.ListOptions{All: true})\nif err != nil {\n\tif isConnectionReset(err) {\n\t\twidget.reconnect() // rebuild client after daemon restart\n\t}\n\twidget.displayBuffer = \"container list unavailable: \" + err.Error()\n\treturn\n}","preventionTips":["Ping the daemon before list calls and rebuild the client on stale connections.","Prevent laptop sleep/suspend of Docker Desktop during long sessions.","Keep SSH tunnels to remote daemons alive (autossh) when using DOCKER_HOST over SSH."],"tags":["docker","containers","network","go"],"backgroundTag":"docker-daemon-unreachable","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"}