{"record":{"id":"6c60b189a0e4ac8a","repo":"hasura/graphql-engine","slug":"parsing-yaml-metadata-to-json-w","errorCode":null,"errorMessage":"parsing yaml metadata to json: %w","messagePattern":"parsing yaml metadata to json: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/metadata_handlers.go","lineNumber":373,"sourceCode":"\t}\n\n\tif o.DryRun {\n\t\tif len(o.rawOutput) == 0 {\n\t\t\to.rawOutput = string(rawOutputFormatJSON)\n\t\t}\n\n\t\terr := writeByOutputFormat(o.EC.Stdout, localMetadataBytes, rawOutputFormat(o.rawOutput))\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"displaying metadata failed: %w\", err))\n\t\t}\n\n\t\treturn nil\n\t}\n\n\tif mode == cli.MetadataModeYAML {\n\t\tlocalMetadataBytes, err = metadatautil.YAMLToJSON(localMetadataBytes)\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"parsing yaml metadata to json: %w\", err))\n\t\t}\n\t}\n\n\tvar metadata any\n\n\terr = json.Unmarshal(localMetadataBytes, &metadata)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"parsing metadata as json: %w\", err))\n\t}\n\n\tif o.EC.Config.Version == cli.V2 {\n\t\t_, err := cli.GetCommonMetadataOps(o.EC).\n\t\t\tReplaceMetadata(bytes.NewReader(localMetadataBytes))\n\t\tif err != nil {\n\t\t\treturn errors.E(op, err)\n\t\t}\n\n\t\treturn nil","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/metadata_handlers.go#L355-L391","documentation":"When applying YAML-mode metadata, the CLI first converts the local YAML file to JSON via metadatautil.YAMLToJSON. This error means the local metadata file is not valid YAML (or contains YAML structures that cannot be represented in JSON), so the apply cannot proceed.","triggerScenarios":"`metadata apply` in YAML mode where the metadata file has YAML syntax errors: bad indentation, tabs, duplicate keys, unclosed quotes, or YAML aliases/constructs with no JSON equivalent (e.g. non-string map keys are fine, but binary/odd tags are not).","commonSituations":"Hand-edited metadata.yaml with indentation mistakes; copy-pasted snippets using tabs instead of spaces; merge conflict markers (<<<<<<<) left in the file; YAML converted from another tool with unsupported features like duplicate keys.","solutions":["Lint the file with yq or a YAML validator to pinpoint the syntax error","Fix indentation (spaces, not tabs), remove merge-conflict markers, deduplicate keys","If unsure which section breaks, split the file and validate sections incrementally","Consider regenerating the file via `metadata export -o yaml` from a known-good server and re-applying your changes on top"],"exampleFix":"# before\nhasura metadata apply  # parsing yaml metadata to json (bad indentation)\n# after\nyq metadata.yaml  # locate the error, fix indentation, then re-run apply","handlingStrategy":"validation","validationCode":"// validate YAML before apply (YAML mode)\ndata, _ := os.ReadFile(ec.MetadataFile)\nvar v any\nif err := yaml.Unmarshal(data, &v); err != nil {\n  return fmt.Errorf(\"metadata YAML invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := apply(o, cli.MetadataModeYAML); err != nil {\n  if strings.Contains(err.Error(), \"parsing yaml metadata to json\") {\n    // run yq on the file to find the syntax error, fix, retry\n  }\n}","preventionTips":["Use spaces (never tabs) in metadata.yaml","Lint YAML in CI before apply","Regenerate from `metadata export -o yaml` rather than hand-writing large files"],"tags":["metadata","apply","yaml","parsing","cli"],"backgroundTag":"yaml-parse-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}