{"record":{"id":"65a2ca90f0cb94f0","repo":"docker/cli","slug":"error-while-getting-existing-contexts-w","errorCode":null,"errorMessage":"error while getting existing contexts: %w","messagePattern":"error while getting existing contexts: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/context/create.go","lineNumber":125,"sourceCode":"\t\t\tdocker.DockerEndpoint: *dockerTLS,\n\t\t}\n\t}\n\tif err := validateEndpoints(contextMetadata); err != nil {\n\t\treturn err\n\t}\n\tif err := contextStore.CreateOrUpdate(contextMetadata); err != nil {\n\t\treturn err\n\t}\n\treturn contextStore.ResetTLSMaterial(name, &contextTLSData)\n}\n\nfunc checkContextNameForCreation(s store.Reader, name string) error {\n\tif err := store.ValidateContextName(name); err != nil {\n\t\treturn err\n\t}\n\tif _, err := s.GetMetadata(name); !errdefs.IsNotFound(err) {\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error while getting existing contexts: %w\", err)\n\t\t}\n\t\treturn fmt.Errorf(\"context %q already exists\", name)\n\t}\n\treturn nil\n}\n\nfunc createFromExistingContext(s store.ReaderWriter, name string, fromContextName string, opts createOptions) error {\n\tif len(opts.endpoint) != 0 {\n\t\treturn errors.New(\"cannot use --docker flag when --from is set\")\n\t}\n\treader := store.Export(fromContextName, &descriptionDecorator{\n\t\tReader:      s,\n\t\tdescription: opts.description,\n\t})\n\tdefer reader.Close()\n\treturn store.Import(name, s, reader)\n}\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/context/create.go#L107-L143","documentation":"Thrown by checkContextNameForCreation when GetMetadata returns an error that is NOT a not-found error. The function expects either success (context exists) or a clean not-found; any other store error (corruption, I/O, permission) surfaces here.","triggerScenarios":"Creating a context while the context store on disk is corrupted or inaccessible. The store.GetMetadata call returns a generic error rather than errdefs.NotFound.","commonSituations":"Context store files under ~/.docker/contexts damaged; permission denied on the store directory; partial write left inconsistent metadata; Docker Desktop sync issue; migrating between machines with a broken copy of ~/.docker.","solutions":["Check store permissions: ls -la ~/.docker/contexts/meta","Inspect for corruption: docker context ls (may also error)","Back up then remove the corrupted context meta and recreate: rm -rf ~/.docker/contexts (use with caution)","Restart the Docker daemon/client to re-initialize the store"],"exampleFix":"# before (store corrupted)\ndocker context create newctx --docker host=unix:///var/run/docker.sock\n# after fixing permissions\nchmod -R u+rwX ~/.docker/contexts\ndocker context create newctx --docker host=unix:///var/run/docker.sock","handlingStrategy":"try-catch","validationCode":"// Probe store health before creating a context.\nif _, err := store.List(ctx); err != nil {\n    return fmt.Errorf(\"context store unhealthy: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := runCreate(...); err != nil {\n    var nfe interface{ NotFound() bool }\n    if !errors.As(err, &nfe) && strings.Contains(err.Error(), \"error while getting existing contexts\") {\n        // offer to reset the store\n    }\n}","preventionTips":["Back up ~/.docker before migration","Run docker context ls as a smoke test in provisioning scripts"],"tags":["docker","context","store","filesystem","corruption"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}