docker/cli · error
parsing
Error message
parsing %s: %v
What it means
Returned by getByID when the context's meta.json fails to unmarshal into the base untypedContextMetadata struct (Name/Metadata/Endpoints). The file exists but its top-level JSON is malformed.
Solutions
- Recreate the context (`docker context rm <name>` then `docker context create`); if rm also fails on parse, remove the dir under ~/.docker/contexts/meta/<hash> manually.
- Validate the JSON: `jq . ~/.docker/contexts/meta/<hash>/meta.json` to see the exact parse error.
- Restore meta.json from a prior export/backup.
Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate meta.json before relying on the store to read it.
func validMetaJSON(p string) bool {
b, err := os.ReadFile(p)
if err != nil {
return false
}
return json.Valid(b)
} Prevention
- Never hand-edit meta.json; use docker context commands.
- Back up / export contexts so a corrupted meta.json is recoverable.
- Validate suspect JSON with `jq .` to localize the parse error.
When it happens
Trigger: meta.json exists but contains invalid JSON: truncated, hand-edited with a syntax error, wrong encoding (e.g. UTF-16 BOM), or a partial/garbled write.
Common situations: Disk full during a write; manual edits to meta.json; copy/sync corruption; a third-party tool that wrote bad JSON; process killed mid-write.
Related errors
- context metadata is not a valid DockerContext
- error while getting existing contexts
- failed to read metadata
- unexpected hook response type
- conflicting options: cannot specify both --host and…
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/b2de4f700a80ca83.
Report an issue: GitHub.
Appendix: source
Thrown at cli/context/store/metadatastore.go:85
}
return m, nil
}
func (s *metadataStore) getByID(id contextdir) (Metadata, error) {
fileName := filepath.Join(s.contextDir(id), metaFile)
bytes, err := os.ReadFile(fileName)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return Metadata{}, notFound(fmt.Errorf("context not found: %w", err))
}
return Metadata{}, err
}
var untyped untypedContextMetadata
r := Metadata{
Endpoints: make(map[string]any),
}
if err := json.Unmarshal(bytes, &untyped); err != nil {
return Metadata{}, fmt.Errorf("parsing %s: %v", fileName, err)
}
r.Name = untyped.Name
if r.Metadata, err = parseTypedOrMap(untyped.Metadata, s.config.contextType); err != nil {
return Metadata{}, fmt.Errorf("parsing %s: %v", fileName, err)
}
for k, v := range untyped.Endpoints {
if r.Endpoints[k], err = parseTypedOrMap(v, s.config.endpointTypes[k]); err != nil {
return Metadata{}, fmt.Errorf("parsing %s: %v", fileName, err)
}
}
return r, err
}
func (s *metadataStore) remove(name string) error {
if err := os.RemoveAll(s.contextDir(contextdirOf(name))); err != nil {
return fmt.Errorf("failed to remove metadata: %w", err)
}
return nilView on GitHub (pinned to 4f84911bfe)