{"record":{"id":"f11aec493fb52a6e","repo":"hasura/graphql-engine","slug":"failed-to-export-metadata-w","errorCode":null,"errorMessage":"failed to export metadata: %w","messagePattern":"failed to export metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/metadata_export.go","lineNumber":110,"sourceCode":"\t}\n\n\terr := getMetadataModeHandler(o.EC.MetadataMode).Export(o)\n\tif err != nil {\n\t\treturn errors.E(op, err)\n\t}\n\n\treturn nil\n}\n\nfunc getMetadataFromServerAndWriteToStdoutByFormat(\n\tec *cli.ExecutionContext,\n\tformat rawOutputFormat,\n) error {\n\tvar op errors.Op = \"commands.getMetadataFromServerAndWriteToStdoutByFormat\"\n\n\tmetadataReader, err := cli.GetCommonMetadataOps(ec).ExportMetadata()\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"failed to export metadata: %w\", err))\n\t}\n\n\tjsonMetadata, err := io.ReadAll(metadataReader)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"reading metadata failed: %w\", err))\n\t}\n\n\tif err := writeByOutputFormat(ec.Stdout, jsonMetadata, format); err != nil {\n\t\treturn errors.E(op, err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":92,"sourceCodeEnd":124,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/metadata_export.go#L92-L124","documentation":"getMetadataFromServerAndWriteToStdoutByFormat exports metadata from the Hasura server via the common metadata ops; any failure of that export call is wrapped as 'failed to export metadata'. The underlying cause is usually an HTTP-level or server-side failure (auth, connectivity, or the server rejecting the export_metadata request).","triggerScenarios":"Running `hasura metadata export --output-format json|yaml` (stdout mode) or code calling getMetadataFromServerAndWriteToStdoutByFormat when ExportMetadata fails: wrong admin secret, unreachable endpoint, server error on the export_metadata API.","commonSituations":"Expired/rotated admin secret, hasura cloud vs local endpoint confusion, server behind a proxy that mangles the API response, or CLI/server version incompatibility in the metadata API.","solutions":["Verify endpoint and admin secret flags/config are correct and current","Confirm server reachability and health (curl <endpoint>/healthz)","Inspect the wrapped error for HTTP status codes to distinguish 401/403 auth from 5xx server errors","Align CLI version with server version and retry"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# Shell: verify auth+reachability first\ncurl -fsS -H \"X-Hasura-Admin-Secret: $SECRET\" \"$ENDPOINT/v1/metadata\" \\\n  -d '{\"type\":\"export_metadata\"}' >/dev/null || { echo 'export precheck failed'; exit 1; }\nhasura metadata export --output-format json","typeGuard":null,"tryCatchPattern":"// Go: retry with backoff on transient export failures\nvar meta io.Reader\nvar err error\nfor i := 0; i < 3; i++ {\n  meta, err = cli.GetCommonMetadataOps(ec).ExportMetadata()\n  if err == nil { break }\n  time.Sleep(time.Second * time.Duration(i+1))\n}","preventionTips":["Validate admin secret and endpoint in config before export","Pin CLI/server versions together"],"tags":["metadata-export","hasura-api","network","auth"],"backgroundTag":"hasura-api-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}