{"id":"b6017a4789882042","repo":"docker/cli","slug":"context-metadata-is-not-a-valid-dockercontext","errorCode":null,"errorMessage":"context metadata is not a valid DockerContext","messagePattern":"context metadata is not a valid DockerContext","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/context.go","lineNumber":61,"sourceCode":"\t\t\tif dc.AdditionalFields == nil {\n\t\t\t\tdc.AdditionalFields = make(map[string]any)\n\t\t\t}\n\t\t\tdc.AdditionalFields[k] = v\n\t\t}\n\t}\n\treturn nil\n}\n\n// GetDockerContext extracts metadata from stored context metadata\nfunc GetDockerContext(storeMetadata store.Metadata) (DockerContext, error) {\n\tif storeMetadata.Metadata == nil {\n\t\t// can happen if we save endpoints before assigning a context metadata\n\t\t// it is totally valid, and we should return a default initialized value\n\t\treturn DockerContext{}, nil\n\t}\n\tres, ok := storeMetadata.Metadata.(DockerContext)\n\tif !ok {\n\t\treturn DockerContext{}, errors.New(\"context metadata is not a valid DockerContext\")\n\t}\n\tif storeMetadata.Name == DefaultContextName {\n\t\tres.Description = \"Current DOCKER_HOST based configuration\"\n\t}\n\treturn res, nil\n}\n","sourceCodeStart":43,"sourceCodeEnd":68,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/context.go#L43-L68","documentation":"GetDockerContext converts the untyped store.Metadata.Metadata field into the typed DockerContext struct via a Go type assertion. The store deserializes metadata using a config function registered by the CLI; if the stored value is present but is not a DockerContext (assertion `storeMetadata.Metadata.(DockerContext)` fails), this error is returned. It signals corrupted or foreign-format context metadata rather than a missing one (nil metadata is treated as valid and returns a zero value).","triggerScenarios":"Calling command.GetDockerContext on a store.Metadata whose Metadata field holds a different concrete type — e.g. a context store read without the CLI's metadata type registration, metadata written by third-party tooling embedding docker/cli with a different config, or a hand-edited/corrupted meta.json under ~/.docker/contexts/meta/<sha>/ that unmarshals into an unexpected type.","commonSituations":"Programs importing docker/cli as a library and constructing a context store with their own store.NewConfig registration then passing results to CLI helpers; corrupted context files after disk issues or manual edits; mixing incompatible docker/cli versions that changed metadata typing.","solutions":["Recreate the affected context: `docker context rm <name>` (or delete its directory under ~/.docker/contexts/meta/) then `docker context create <name> --docker host=...`.","If embedding docker/cli, build the store with command.DefaultContextStoreConfig() so metadata unmarshals into command.DockerContext.","Inspect ~/.docker/contexts/meta/*/meta.json for hand-edits or corruption and restore valid JSON."],"exampleFix":"// before (library use)\nst := store.New(dir, store.NewConfig(func() any { return &map[string]any{} }))\n// after\nst := store.New(dir, command.DefaultContextStoreConfig())","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","context","metadata","type-assertion"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}