{"record":{"id":"93d13b0bf7b4dec8","repo":"juanfont/headscale","slug":"parsing-docker-context-w","errorCode":null,"errorMessage":"parsing docker context: %w","messagePattern":"parsing docker context: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/hi/docker.go","lineNumber":495,"sourceCode":"\tif len(clientOpts) == 1 {\n\t\tclientOpts = append(clientOpts, client.FromEnv)\n\t}\n\n\treturn client.NewClientWithOpts(clientOpts...)\n}\n\n// getCurrentDockerContext retrieves the current Docker context information.\nfunc getCurrentDockerContext(ctx context.Context) (*DockerContext, error) {\n\tcmd := exec.CommandContext(ctx, \"docker\", \"context\", \"inspect\")\n\n\toutput, err := cmd.Output()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting docker context: %w\", err)\n\t}\n\n\tvar contexts []DockerContext\n\tif err := json.Unmarshal(output, &contexts); err != nil { //nolint:noinlineerr\n\t\treturn nil, fmt.Errorf(\"parsing docker context: %w\", err)\n\t}\n\n\tif len(contexts) > 0 {\n\t\treturn &contexts[0], nil\n\t}\n\n\treturn nil, ErrNoDockerContext\n}\n\n// getDockerSocketPath returns the correct Docker socket path for the current context.\nfunc getDockerSocketPath() string {\n\t// Always use the default socket path for mounting since Docker handles\n\t// the translation to the actual socket (e.g., colima socket) internally\n\treturn \"/var/run/docker.sock\"\n}\n\n// checkImageAvailableLocally checks if the specified Docker image is available locally.\nfunc checkImageAvailableLocally(ctx context.Context, cli *client.Client, imageName string) (bool, error) {","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/hi/docker.go#L477-L513","documentation":"Returned by `getCurrentDockerContext` when `docker context inspect` succeeded but its stdout was not valid JSON matching []DockerContext. The docker CLI usually emits a single object unless `-f` is set, so shape/type mismatches are the classic cause; older/newer CLI output format changes can also break the unmarshal.","triggerScenarios":"CLI version that prints an object instead of an array (or vice versa); localized or otherwise modified CLI output; empty-but-zero-exit output; fields whose JSON types don't match the DockerContext struct.","commonSituations":"Upgrading the docker CLI to a version with changed context inspect output; wrapper scripts that prepend output to docker; unusual DOCKER_CONFIG JSON.","solutions":["Run `docker context inspect` manually and check whether output is `[{...}]` or `{...}`.","Upgrade/downgrade docker CLI to a mainstream version (or the one pinned in the repo's nix shell).","Remove any shell wrappers/aliases that alter docker output.","As a workaround, `docker context use default` — the default context path avoids the inspect dependency."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// pre-validate the inspect output shape\nout, err := exec.Command(\"docker\", \"context\", \"inspect\").Output()\nif err != nil {\n    return err\n}\nif len(out) > 0 && out[0] != '[' {\n    out = append([]byte{'['}, append(out, ']')...) // normalize object -> array\n}\nvar ctxs []DockerContext\nreturn json.Unmarshal(out, &ctxs)","typeGuard":null,"tryCatchPattern":"if err := getCurrentDockerContext(ctx); err != nil {\n    if strings.Contains(err.Error(), \"parsing docker context\") {\n        // CLI output shape mismatch: pin a mainstream docker CLI version or\n        // `docker context use default` to bypass the inspect path\n    }\n}","preventionTips":["Use the repo's nix-developed toolchain, which pins a known docker CLI.","Avoid shell wrappers that alter docker output.","Run `docker context inspect` manually after CLI upgrades to confirm array output."],"tags":["docker","json","docker-context","version-compatibility"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}