hasura/graphql-engine · error
cannot unmarshal server metadata to json: %w
Error message
cannot unmarshal server metadata to json: %w
What it means
Companion to the local-side error: during a json-type metadata diff between directories, converting the old directory's YAML metadata to JSON failed. The wrapped error identifies whether the YAML was unparseable or the resulting JSON could not be indented. Only the old (second) side's files are implicated.
Source
Thrown at cli/commands/metadata_diff.go:193
opts.projectMetadataHandler.SetMetadataObjects(
projectmetadata.GetMetadataObjectsWithDir(opts.ec, opts.fromProjectDirectory),
)
oldYaml, err := opts.projectMetadataHandler.BuildYAMLMetadata()
if err != nil {
return errors.E(op, err)
}
switch opts.diffType {
case DifftypeJSON:
newJson, err := convertYamlToJsonWithIndent(newYaml)
if err != nil {
return errors.E(op, fmt.Errorf("cannot unmarshal local metadata to json: %w", err))
}
oldJson, err := convertYamlToJsonWithIndent(oldYaml)
if err != nil {
return errors.E(op, fmt.Errorf("cannot unmarshal server metadata to json: %w", err))
}
if err := printMyersDiff(
string(newJson),
string(oldJson),
opts.toFriendlyName,
opts.fromFriendlyName,
opts.writer,
opts.disableColor,
); err != nil {
return errors.E(op, err)
}
return nil
case DifftypeYAML:
err := printMyersDiff(
string(newYaml),
string(oldYaml),View on GitHub (pinned to 724551b9ae)
Solutions
- Lint the old directory's YAML files (yq '.' metadata/*.yaml) to find the broken file
- Fix indentation/duplicate-key issues in the old side's metadata
- Re-export a clean baseline: hasura metadata export into the old directory and retry the diff
Defensive patterns
Strategy: validation
Validate before calling
# Shell: lint the old/baseline directory too
for f in olddir/metadata/*.yaml; do yq -e '.' "$f" >/dev/null || { echo "bad: $f"; exit 1; }; done Prevention
- Keep baseline metadata directories clean exports
- Check for merge-conflict markers after git merges
When it happens
Trigger: `hasura metadata diff --type-of-diff json <newDir> <oldDir>` where oldDir's metadata YAML is malformed: invalid syntax, duplicate keys, or merge-conflict remnants in its metadata files.
Common situations: Comparing against a baseline directory that was hand-edited or partially written, checking out an old branch whose metadata has conflict markers, or a stale export directory corrupted on disk.
Related errors
- cannot unmarshal local metadata to json: %w
- cannot convert yaml to json: %w
- cannot indent json: %w
- reading global config file failed: %w
- error in reading %s: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/49c7ca3e9a29e5e2.
Report an issue: GitHub.