{"record":{"id":"ce691a3f5ae9d344","repo":"hasura/graphql-engine","slug":"displaying-metadata-failed-w","errorCode":null,"errorMessage":"displaying metadata failed: %w","messagePattern":"displaying metadata failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/metadata_handlers.go","lineNumber":123,"sourceCode":"\t\t\t// show a warning about change in behaviour\n\t\t\to.rawOutput = string(rawOutputFormatJSON)\n\t\t\to.EC.Logger.Warn(\n\t\t\t\t\"behaviour of --dry-run flag has changed from v2.0.0. It used to show a diff between metadata on server and local project\",\n\t\t\t)\n\t\t\to.EC.Logger.Warn(\n\t\t\t\t\"new behaviour is to output local project metadata as JSON by default. The output format is configurable by -o flag eg: `hasura metadata apply --dry-run -o yaml`\",\n\t\t\t)\n\t\t\to.EC.Logger.Warn(\n\t\t\t\t\"the old behaviour can be achieved using `hasura metadata diff` command\",\n\t\t\t)\n\t\t}\n\n\t\tif err := writeByOutputFormat(\n\t\t\to.EC.Stdout,\n\t\t\tprojectMetadataJSON,\n\t\t\trawOutputFormat(o.rawOutput),\n\t\t); err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"displaying metadata failed: %w\", err))\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (m *metadataModeDirectoryHandler) Diff(o *MetadataDiffOptions) error {\n\tvar op errors.Op = \"commands.metadataModeDirectoryHandler.Diff\"\n\n\targs := o.Args\n\tmessageFormat := \"Showing diff between %s and %s...\"\n\tmetadataHandler := projectmetadata.NewHandlerFromEC(o.EC)\n\tfromFriendlyName := \"project\"\n\ttoFriendlyName := \"server\"\n\tfromDirectory, toDirectory := \"\", \"\"\n\n\tswitch len(args) {\n\tcase 0:","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/metadata_handlers.go#L105-L141","documentation":"During a dry-run `metadata apply`, after the JSON metadata is successfully built, the CLI attempts to print it to stdout in the requested raw output format (JSON or YAML). This error means the built metadata could not be rendered/written in the chosen format — almost always because the metadata blob is not valid for the requested conversion (e.g. invalid JSON for a YAML conversion) or stdout is not writable.","triggerScenarios":"`metadata apply --dry-run` with a raw output format where writeByOutputFormat fails: invalid JSON bytes being converted, a JSON-to-YAML conversion error, or a closed/unwritable stdout stream.","commonSituations":"Passing --raw-output yaml when the built metadata contains values that fail YAML marshalling; piping output to a closed pipe (e.g. `| head` causing SIGPIPE/EPIPE); server returning malformed JSON metadata.","solutions":["Retry with the default JSON raw output format to see if the conversion is the culprit","Inspect the wrapped error to see whether it is a marshalling error or a write error","Avoid piping the dry-run output to consumers that close the pipe early (use a file redirect instead)","If metadata itself is malformed, export and inspect it with `metadata export` to locate the invalid structure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := opts.Apply()\nif err != nil && strings.Contains(err.Error(), \"displaying metadata failed\") {\n  // fall back to JSON output or write to a file instead of stdout\n}","preventionTips":["Default to JSON raw output for dry runs","Avoid piping CLI output to short-lived processes like head","Redirect output to a file when the metadata document is large"],"tags":["metadata","dry-run","output-format","stdout","cli"],"backgroundTag":"output-formatting-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}