{"record":{"id":"82d91e783fb66fe5","repo":"docker/cli","slug":"failed-to-read-metadata-w","errorCode":null,"errorMessage":"failed to read metadata: %w","messagePattern":"failed to read metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/context/store/metadatastore.go","lineNumber":121,"sourceCode":"\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\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"failed to read metadata: %w\", err)\n\t\t}\n\t\tres = append(res, c)\n\t}\n\tsort.Slice(res, func(i, j int) bool {\n\t\treturn sortorder.NaturalLess(res[i].Name, res[j].Name)\n\t})\n\treturn res, nil\n}\n\nfunc isContextDir(path string) bool {\n\ts, err := os.Stat(filepath.Join(path, metaFile))\n\tif err != nil {\n\t\treturn false\n\t}\n\treturn !s.IsDir()\n}\n\nfunc listRecursivelyMetadataDirs(root string) ([]string, error) {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/context/store/metadatastore.go#L103-L139","documentation":"Returned by ContextStore.List / metadataStore.list when reading one of the context directories fails with an error other than 'not exist'. Listing iterates all context dirs; not-exist errors are skipped, but any other error (parse or I/O on a single context) aborts the entire list.","triggerScenarios":"Calling store.List() (e.g. `docker context ls`) when one context's meta.json is corrupt or unreadable; a single bad context poisons listing for the whole store.","commonSituations":"One corrupted context making `docker context ls` fail; permission denied on one context dir; partial write leaving one meta.json invalid.","solutions":["Identify and remove/repair the offending context dir by checking each meta.json under ~/.docker/contexts/meta/.","Fix permissions on the unreadable dir.","Remove the broken context (manually if `docker context rm` also fails) and recreate it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"list, err := store.List()\nif err != nil {\n    // One bad context aborts listing — locate the offending dir under\n    // ~/.docker/contexts/meta/*/meta.json and repair/remove it, then retry.\n    return err\n}","preventionTips":["Validate each meta.json when iterating contexts manually so one bad entry doesn't abort.","Quarantine corrupted context dirs so `docker context ls` keeps working.","Back up the contexts dir before bulk operations."],"tags":["context","list","corruption","filesystem"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}