{"record":{"id":"0978c505ff79d217","repo":"hasura/graphql-engine","slug":"parsing-metadata-to-yaml-w","errorCode":null,"errorMessage":"parsing metadata to yaml: %w","messagePattern":"parsing metadata to yaml: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/metadata_handlers.go","lineNumber":333,"sourceCode":"func export(o *MetadataExportOptions, mode cli.MetadataMode) error {\n\tvar op errors.Op = \"commands.export\"\n\n\tmetadata, err := ec.APIClient.V1Metadata.ExportMetadata()\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"exporting metadata from server: %w\", err))\n\t}\n\n\tvar metadataBytes []byte\n\n\tmetadataBytes, err = io.ReadAll(metadata)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"reading metadata from response: %w\", err))\n\t}\n\n\tif mode == cli.MetadataModeYAML {\n\t\tmetadataBytes, err = metadatautil.JSONToYAML(metadataBytes)\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"parsing metadata to yaml: %w\", err))\n\t\t}\n\t}\n\n\terr = os.WriteFile(o.EC.MetadataFile, metadataBytes, os.ModePerm)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"writing metadata to file: %w\", err))\n\t}\n\n\treturn nil\n}\n\nfunc apply(o *MetadataApplyOptions, mode cli.MetadataMode) error {\n\tvar (\n\t\top                 errors.Op = \"commands.apply\"\n\t\tlocalMetadataBytes []byte\n\t\terr                error\n\t)\n","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/metadata_handlers.go#L315-L351","documentation":"When exporting metadata in YAML mode, the server's JSON metadata must be converted to YAML via metadatautil.JSONToYAML. This error means that conversion failed — practically, because the JSON returned by the server is malformed or contains structures the converter cannot marshal to YAML.","triggerScenarios":"Running `metadata export --o yaml` (or equivalent) where the fetched metadata bytes are not valid JSON or fail YAML marshalling: truncated server response, unexpected JSON types, encoding issues.","commonSituations":"Server returning an error page or truncated body that still reads successfully but is not the expected JSON document; very old/new server versions emitting JSON structures the CLI converter does not understand; BOM or encoding artifacts in the response.","solutions":["Export in JSON format first to inspect the raw document and confirm it is valid JSON","Update the CLI to a version matching the server's metadata API version","If the JSON is malformed, investigate the server-side metadata state (possible inconsistency) with `metadata inconsistency list`","Report to CLI maintainers if the JSON is valid but conversion still fails (converter bug)"],"exampleFix":"# before\nhasura metadata export -o yaml  # parsing metadata to yaml\n# after\nhasura metadata export -o json  # inspect raw JSON, then convert locally with yq","handlingStrategy":"fallback","validationCode":"// validate JSON before YAML conversion in your own tooling\nvar v any\nif err := json.Unmarshal(metadataBytes, &v); err != nil {\n  // export as JSON instead of YAML\n}","typeGuard":null,"tryCatchPattern":"if err := export(o, cli.MetadataModeYAML); err != nil {\n  if strings.Contains(err.Error(), \"parsing metadata to yaml\") {\n    return export(o, cli.MetadataModeJSON) // fallback format\n  }\n}","preventionTips":["Export as JSON and convert to YAML locally with yq when servers are version-skewed","Keep CLI version matched to server version","Validate server responses before format conversions in custom scripts"],"tags":["metadata","export","yaml","json-conversion","cli"],"backgroundTag":"json-yaml-conversion-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}