{"record":{"id":"5aa199d6da0ede5b","repo":"docker/cli","slug":"default-context-cannot-be-removed","errorCode":null,"errorMessage":"default context cannot be removed","messagePattern":"default context cannot be removed","errorType":"validation","errorClass":"invalidParameterErr","httpStatus":null,"severity":"error","filePath":"cli/command/defaultcontextstore.go","lineNumber":129,"sourceCode":"\tdefaultContext, err := s.Resolver()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn append(contextList, defaultContext.Meta), nil\n}\n\n// CreateOrUpdate is not allowed for the default context and fails\nfunc (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error {\n\tif meta.Name == DefaultContextName {\n\t\treturn invalidParameter(errors.New(\"default context cannot be created nor updated\"))\n\t}\n\treturn s.Store.CreateOrUpdate(meta)\n}\n\n// Remove is not allowed for the default context and fails\nfunc (s *ContextStoreWithDefault) Remove(name string) error {\n\tif name == DefaultContextName {\n\t\treturn invalidParameter(errors.New(\"default context cannot be removed\"))\n\t}\n\treturn s.Store.Remove(name)\n}\n\n// GetMetadata implements store.Store's GetMetadata\nfunc (s *ContextStoreWithDefault) GetMetadata(name string) (store.Metadata, error) {\n\tif name == DefaultContextName {\n\t\tdefaultContext, err := s.Resolver()\n\t\tif err != nil {\n\t\t\treturn store.Metadata{}, err\n\t\t}\n\t\treturn defaultContext.Meta, nil\n\t}\n\treturn s.Store.GetMetadata(name)\n}\n\n// ResetTLSMaterial is not implemented for default context and fails\nfunc (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.ContextTLSData) error {","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/defaultcontextstore.go#L111-L147","documentation":"ContextStoreWithDefault.Remove() is the store-level mirror of the remove-command guard: it refuses to Remove(\"default\") because the default context is not a deletable stored entity. Any code path that reaches the store with the reserved name gets an invalidParameter error here.","triggerScenarios":"Calling ContextStoreWithDefault.Remove(\"default\") directly, or a higher-level command that did not pre-filter the name.","commonSituations":"A generic context-management library enumerating and deleting contexts; the rm command's guard was bypassed (e.g. an older client path).","solutions":["Skip the \"default\" name before calling Remove","Use DOCKER_CONTEXT to switch away rather than deleting default","Guard callers against the reserved DefaultContextName constant"],"exampleFix":"// before\nstore.Remove(\"default\")\n// after\nif name != command.DefaultContextName { store.Remove(name) }","handlingStrategy":"validation","validationCode":"if name == command.DefaultContextName {\n    return nil // no-op: default context is not deletable\n}\nreturn store.Remove(name)","typeGuard":"func isReservedContextName(name string) bool { return name == command.DefaultContextName }","tryCatchPattern":null,"preventionTips":["Exclude DefaultContextName from any Remove() call path","Use DOCKER_CONTEXT to switch away rather than deleting default","Treat the reserved name as non-removable in context-management libraries"],"tags":["context","store","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}