{"record":{"id":"9980bb886076b006","repo":"wtfutil/wtf","slug":"could-not-create-client-w-9980bb","errorCode":null,"errorMessage":"could not create client: %w","messagePattern":"could not create client: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/docker/widget.go","lineNumber":28,"sourceCode":"\ntype Widget struct {\n\tview.TextWidget\n\tcli           *client.Client\n\tsettings      *Settings\n\tdisplayBuffer string\n}\n\nfunc NewWidget(tviewApp *tview.Application, redrawChan chan bool, pages *tview.Pages, settings *Settings) *Widget {\n\twidget := Widget{\n\t\tTextWidget: view.NewTextWidget(tviewApp, redrawChan, pages, settings.Common),\n\t\tsettings:   settings,\n\t}\n\n\twidget.View.SetScrollable(true)\n\n\tcli, err := client.NewClientWithOpts(client.FromEnv)\n\tif err != nil {\n\t\twidget.displayBuffer = fmt.Errorf(\"could not create client: %w\", err).Error()\n\t} else {\n\t\twidget.cli = cli\n\t}\n\n\twidget.refreshDisplayBuffer()\n\n\treturn &widget\n}\n\n/* -------------------- Exported Functions -------------------- */\n\nfunc (widget *Widget) Refresh() {\n\twidget.refreshDisplayBuffer()\n\twidget.Redraw(widget.display)\n}\n\n/* -------------------- Unexported Functions -------------------- */\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/modules/docker/widget.go#L10-L46","documentation":"NewWidget builds the Docker client with client.NewClientWithOpts(client.FromEnv), which reads DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH etc. from the environment. If client construction fails (invalid DOCKER_HOST URL, missing/malformed TLS config, unparsable env), the error is stored in the widget's displayBuffer as \"could not create client\". This happens before any daemon call — it is a configuration failure.","triggerScenarios":"client.FromEnv fails: DOCKER_HOST is not a valid URL (e.g., \"myhost\" instead of \"tcp://myhost:2375\"), DOCKER_CERT_PATH files missing/unreadable with DOCKER_TLS_VERIFY=1, or unsupported scheme.","commonSituations":"Copy-pasted DOCKER_HOST from a teammate with a typo, switched from Docker Desktop to colima/podman without updating the socket path, missing cert files after machine migration, or env vars set in one shell but not the one launching the app.","solutions":["Validate DOCKER_HOST parses as a URL: docker -H \"$DOCKER_HOST\" info.","Fix the scheme — use tcp://, unix://, or npipe:// prefixes explicitly.","If DOCKER_TLS_VERIFY=1, confirm DOCKER_CERT_PATH contains ca.pem, cert.pem, key.pem.","Unset DOCKER_* vars to fall back to the default local socket if you intend local usage."],"exampleFix":"// before\ncli, err := client.NewClientWithOpts(client.FromEnv)\nif err != nil {\n\twidget.displayBuffer = fmt.Errorf(\"could not create client: %w\", err).Error()\n}\n// after\nhost := os.Getenv(\"DOCKER_HOST\")\nif host != \"\" && !strings.Contains(host, \"://\") {\n\thost = \"tcp://\" + host\n\tos.Setenv(\"DOCKER_HOST\", host)\n}\ncli, err := client.NewClientWithOpts(client.FromEnv)\nif err != nil {\n\twidget.displayBuffer = fmt.Errorf(\"could not create client: %w\", err).Error()\n}","handlingStrategy":"validation","validationCode":"host := os.Getenv(\"DOCKER_HOST\")\nif host != \"\" {\n\tif _, err := url.Parse(host); err != nil || !strings.Contains(host, \"://\") {\n\t\treturn fmt.Errorf(\"invalid DOCKER_HOST %q: must be a URL like tcp://host:2375 or unix:///path\", host)\n\t}\n}\nif os.Getenv(\"DOCKER_TLS_VERIFY\") != \"\" {\n\tfor _, f := range []string{\"ca.pem\", \"cert.pem\", \"key.pem\"} {\n\t\tif _, err := os.Stat(filepath.Join(os.Getenv(\"DOCKER_CERT_PATH\"), f)); err != nil {\n\t\t\treturn fmt.Errorf(\"missing TLS cert %s in DOCKER_CERT_PATH\", f)\n\t\t}\n\t}\n}","typeGuard":"func validDockerHost(host string) bool {\n\tu, err := url.Parse(host)\n\treturn err == nil && u.Scheme != \"\" && (u.Scheme == \"unix\" || u.Scheme == \"tcp\" || u.Scheme == \"npipe\" || u.Scheme == \"ssh\")\n}","tryCatchPattern":"cli, err := client.NewClientWithOpts(client.FromEnv)\nif err != nil {\n\twidget.displayBuffer = fmt.Sprintf(\"docker client config invalid: %v — check DOCKER_HOST/DOCKER_CERT_PATH\", err)\n\treturn\n}","preventionTips":["Always use fully qualified DOCKER_HOST values (scheme included).","Run `docker -H \"$DOCKER_HOST\" info` to validate env config before launching the app.","Unset DOCKER_* variables when you intend to use the default local socket."],"tags":["docker","configuration","env-vars","go"],"backgroundTag":"invalid-docker-host-config","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"}