{"record":{"id":"635491a3e1c20f05","repo":"docker/cli","slug":"context-q-does-not-exist","errorCode":null,"errorMessage":"context %q does not exist","messagePattern":"context %q does not exist","errorType":"validation","errorClass":"notFoundErr","httpStatus":null,"severity":"warning","filePath":"cli/command/context/remove.go","lineNumber":78,"sourceCode":"\t\t\treturn err\n\t\t}\n\t}\n\n\tif !force {\n\t\t// TODO(thaJeztah): instead of checking before removing, can we make ContextStore().Remove() return a proper errdef and ignore \"not found\" errors?\n\t\tif err := checkContextExists(dockerCli, name); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn dockerCli.ContextStore().Remove(name)\n}\n\n// checkContextExists returns an error if the context directory does not exist.\nfunc checkContextExists(dockerCli command.Cli, name string) error {\n\tcontextDir := dockerCli.ContextStore().GetStorageInfo(name).MetadataPath\n\t_, err := os.Stat(contextDir)\n\tif os.IsNotExist(err) {\n\t\treturn notFoundErr{fmt.Errorf(\"context %q does not exist\", name)}\n\t}\n\t// Ignore other errors; if relevant, they will produce an error when\n\t// performing the actual delete.\n\treturn nil\n}\n\ntype notFoundErr struct{ error }\n\nfunc (notFoundErr) NotFound() {}\n","sourceCodeStart":60,"sourceCodeEnd":88,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/context/remove.go#L60-L88","documentation":"Returned by checkContextExists (remove.go:78) as a notFoundErr when os.Stat on the context's MetadataPath reports os.IsNotExist. This pre-check runs before the actual Remove call so that a missing context produces a clear 'does not exist' message rather than a generic store error. The wrapped error implements the NotFound() marker interface.","triggerScenarios":"Running 'docker context rm <name>' (without -f) where <name> is not 'default' but no metadata file exists on disk for it. This includes typos, contexts removed out-of-band, or names that were never created. With -f the pre-check is skipped and the underlying store.Remove determines the outcome.","commonSituations":"Typo in the context name; context already deleted; context name taken from stale documentation; home/config directory reset so the contexts directory is empty.","solutions":["List existing contexts to confirm the name: 'docker context ls'.","Check spelling and tab-complete against 'docker context ls --format '{{.Name}}''.","If the contexts directory was wiped, recreate needed contexts with 'docker context create'.","Pass -f only if you intentionally want to bypass the existence check (e.g., cleaning stale references)."],"exampleFix":"# before\ndocker context rm produciton\n# after\ndocker context ls\ndocker context rm production","handlingStrategy":"validation","validationCode":"// Confirm a context exists before attempting removal.\nfunc contextExists(cli command.Cli, name string) bool {\n\tfor _, m := range cli.ContextStore().GetStorageInfo(name).MetadataPath {\n\t\t_ = m // placeholder\n\t}\n\t_, err := os.Stat(cli.ContextStore().GetStorageInfo(name).MetadataPath)\n\treturn !os.IsNotExist(err)\n}","typeGuard":"func isNotFound(err error) bool {\n\tvar nfe interface{ NotFound() bool }\n\treturn errors.As(err, &nfe) && nfe.NotFound()\n}","tryCatchPattern":"if err := cli.ContextRemove(name); err != nil {\n\tvar nfe interface{ NotFound() bool }\n\tif errors.As(err, &nfe) && nfe.NotFound() {\n\t\t// already gone; treat as success in idempotent scripts\n\t}\n}","preventionTips":["List contexts ('docker context ls') before removing.","Make removal scripts idempotent by treating NotFound as success.","Use the NotFound() marker interface rather than string matching."],"tags":["docker-context","remove","not-found","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}