{"record":{"id":"edbccb60ceacd0d3","repo":"docker/cli","slug":"failed-to-remove-metadata-w","errorCode":null,"errorMessage":"failed to remove metadata: %w","messagePattern":"failed to remove metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/context/store/metadatastore.go","lineNumber":101,"sourceCode":"\t}\n\tif err := json.Unmarshal(bytes, &untyped); err != nil {\n\t\treturn Metadata{}, fmt.Errorf(\"parsing %s: %v\", fileName, err)\n\t}\n\tr.Name = untyped.Name\n\tif r.Metadata, err = parseTypedOrMap(untyped.Metadata, s.config.contextType); err != nil {\n\t\treturn Metadata{}, fmt.Errorf(\"parsing %s: %v\", fileName, err)\n\t}\n\tfor k, v := range untyped.Endpoints {\n\t\tif r.Endpoints[k], err = parseTypedOrMap(v, s.config.endpointTypes[k]); err != nil {\n\t\t\treturn Metadata{}, fmt.Errorf(\"parsing %s: %v\", fileName, err)\n\t\t}\n\t}\n\treturn r, err\n}\n\nfunc (s *metadataStore) remove(name string) error {\n\tif err := os.RemoveAll(s.contextDir(contextdirOf(name))); err != nil {\n\t\treturn fmt.Errorf(\"failed to remove metadata: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (s *metadataStore) list() ([]Metadata, error) {\n\tctxDirs, err := listRecursivelyMetadataDirs(s.root)\n\tif err != nil {\n\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn nil, err\n\t}\n\tres := make([]Metadata, 0, len(ctxDirs))\n\tfor _, dir := range ctxDirs {\n\t\tc, err := s.getByID(contextdir(dir))\n\t\tif err != nil {\n\t\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\t\tcontinue","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/context/store/metadatastore.go#L83-L119","documentation":"Returned by metadataStore.remove (reached via ContextStore.Remove -> 510) when os.RemoveAll of the context's metadata directory fails. The wrapped error is the OS error, typically a permission denial or I/O error.","triggerScenarios":"Calling store.Remove(name) / `docker context rm` when the metadata dir or a file within it cannot be deleted: permission denied, read-only filesystem, or a file held open.","commonSituations":"Files created as root but CLI running as a normal user (or vice versa); read-only mount; another process locking files (Windows AV/indexer); NFS permission quirks.","solutions":["Fix ownership/permissions on the context dir under ~/.docker/contexts/meta/<hash> (e.g. `sudo chown -R $USER ~/.docker/contexts`).","Remove the directory manually as the appropriate user: `rm -rf ~/.docker/contexts/meta/<hash>`.","Confirm the filesystem is writable and not mounted read-only."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := store.Remove(name); err != nil {\n    var perr *os.PathError\n    if errors.As(err, &perr) && errors.Is(perr.Err, os.ErrPermission) {\n        // fix ownership/permissions, then retry or remove the dir manually\n    }\n    return err\n}","preventionTips":["Run context-management commands as the user that owns ~/.docker.","Avoid creating context files as root for a non-root user.","After root-created contexts, chown ~/.docker/contexts back to the user."],"tags":["context","filesystem","permissions","cleanup"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}