{"record":{"id":"7ce6b7a851694205","repo":"hasura/graphql-engine","slug":"cannot-unmarshal-local-metadata-to-json-w","errorCode":null,"errorMessage":"cannot unmarshal local metadata to json: %w","messagePattern":"cannot unmarshal local metadata to json: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/metadata_diff.go","lineNumber":188,"sourceCode":"\tnewYaml, err := opts.projectMetadataHandler.BuildYAMLMetadata()\n\tif err != nil {\n\t\treturn errors.E(op, err)\n\t}\n\n\topts.projectMetadataHandler.SetMetadataObjects(\n\t\tprojectmetadata.GetMetadataObjectsWithDir(opts.ec, opts.fromProjectDirectory),\n\t)\n\n\toldYaml, err := opts.projectMetadataHandler.BuildYAMLMetadata()\n\tif err != nil {\n\t\treturn errors.E(op, err)\n\t}\n\n\tswitch opts.diffType {\n\tcase DifftypeJSON:\n\t\tnewJson, err := convertYamlToJsonWithIndent(newYaml)\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"cannot unmarshal local metadata to json: %w\", err))\n\t\t}\n\n\t\toldJson, err := convertYamlToJsonWithIndent(oldYaml)\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"cannot unmarshal server metadata to json: %w\", err))\n\t\t}\n\n\t\tif err := printMyersDiff(\n\t\t\tstring(newJson),\n\t\t\tstring(oldJson),\n\t\t\topts.toFriendlyName,\n\t\t\topts.fromFriendlyName,\n\t\t\topts.writer,\n\t\t\topts.disableColor,\n\t\t); err != nil {\n\t\t\treturn errors.E(op, err)\n\t\t}\n","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/metadata_diff.go#L170-L206","documentation":"While computing a metadata diff of type json between two project directories, the CLI converts each side's YAML metadata to JSON via convertYamlToJsonWithIndent; failure converting the new (local) side produces this error. The wrapped error is either a YAML parse error or a JSON indent failure on that side's metadata files.","triggerScenarios":"Running `hasura metadata diff --type-of-diff json <dir1> <dir2>` (or Diff between directories) where the first/new directory's YAML metadata contains invalid YAML — bad indentation, duplicate keys, tabs, or non-serializable constructs.","commonSituations":"Hand-edited metadata YAML with syntax errors, merge-conflict markers left in files, or a generated metadata directory where a file was truncated mid-write.","solutions":["Locate and fix YAML syntax errors in the new directory's metadata files (hasura metadata export produces valid YAML as a baseline)","Run yq or a YAML linter over the directory to pinpoint the malformed file","Remove leftover git merge-conflict markers (<<<<<<< / >>>>>>>) from metadata files","Regenerate metadata with `hasura metadata export` and re-apply your changes incrementally"],"exampleFix":"# before (tables.yaml with conflict markers)\n<<<<<<< HEAD\n- table: users\n=======\n- table: accounts\n>>>>>>> main\n# after (resolve the conflict)\n- table: users\n- table: accounts","handlingStrategy":"validation","validationCode":"# Shell: lint YAML before diffing\nfor f in newdir/metadata/*.yaml; do yq '.' \"$f\" >/dev/null || exit 1; done\nhasura metadata diff --type-of-diff json newdir olddir","typeGuard":null,"tryCatchPattern":"// Go: pre-convert to catch bad YAML with a clear file name\nfor _, f := range files {\n  if _, err := metadatautil.YAMLToJSON(read(f)); err != nil {\n    return fmt.Errorf(\"%s: %w\", f, err)\n  }\n}","preventionTips":["Lint metadata YAML in CI before diff/apply","Avoid hand-editing exported metadata; regenerate instead"],"tags":["yaml","metadata-diff","parse-error"],"backgroundTag":"yaml-parse-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}