{"record":{"id":"4050ab083a9cef85","repo":"hasura/graphql-engine","slug":"encoding-json-response-from-server-w","errorCode":null,"errorMessage":"encoding json response from server: %w","messagePattern":"encoding json response from server: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli/pkg/metadata/mode_handlers.go","lineNumber":59,"sourceCode":"\tmetadataHandler := projectmetadata.NewHandlerFromEC(p.ec)\n\tif p.ec.Config.Version == cli.V2 {\n\t\tr, err := metadataHandler.V1ApplyMetadata()\n\t\tif err != nil {\n\t\t\treturn nil, errors.E(op, err)\n\t\t}\n\n\t\treturn r, nil\n\t}\n\n\tif p.ec.Config.Version >= cli.V3 {\n\t\treplaceMetadataResponse, err := metadataHandler.V2ApplyMetadata(false)\n\t\tif err != nil {\n\t\t\treturn nil, errors.E(op, err)\n\t\t}\n\n\t\tb := new(bytes.Buffer)\n\t\tif err := json.NewEncoder(b).Encode(replaceMetadataResponse); err != nil {\n\t\t\treturn nil, errors.E(op, fmt.Errorf(\"encoding json response from server: %w\", err))\n\t\t}\n\n\t\treturn b, nil\n\t}\n\n\treturn nil, nil\n}\n\nfunc (m *metadataModeDirectoryHandler) Parse(p *ProjectMetadata) (io.Reader, error) {\n\tvar op errors.Op = \"metadata.metadataModeDirectoryHandler.Parse\"\n\n\tmetadataHandler := projectmetadata.NewHandlerFromEC(p.ec)\n\n\tjsonMetadata, err := metadataHandler.BuildJSONMetadata()\n\tif err != nil {\n\t\treturn nil, errors.E(op, fmt.Errorf(\"parsing project metadata to json failed: %w\", err))\n\t}\n","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/pkg/metadata/mode_handlers.go#L41-L77","documentation":"After a successful metadata replace on the server, the metadata apply handler encodes the replaceMetadataResponse into JSON for display; if json.Encoder fails you get 'encoding json response from server'. Only fails if the response contains values Go's encoding/json cannot serialize (NaN/Inf, unsupported map key types, circular refs).","triggerScenarios":"Calling metadata Apply (e.g. `hasura metadata apply`) when the server's replace-metadata response includes a value that breaks JSON encoding — rare, and usually a sign of an unexpected/proxied response body (e.g. gateway returning HTML that got typed loosely).","commonSituations":"A proxy or middleware mangling the Hasura server response; server versions returning exotic fields; effectively unreachable in normal operation with a genuine Hasura server.","solutions":["Inspect the raw server response (curl the /v1/metadata endpoint with the same request)","Check for a proxy/gateway between CLI and server altering responses","Align CLI and server versions so response shapes match","Report the offending response payload as a bug if it comes from Hasura itself"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if b, err := handler.Apply(&p); err != nil {\n    if strings.Contains(err.Error(), \"encoding json response\") {\n        // dump raw server response and check proxies/version skew\n    }\n}","preventionTips":["Bypass mutating proxies between CLI and server","Match CLI major version to server version","Log raw /v1/metadata responses when debugging"],"tags":["metadata","json-encoding","hasura"],"backgroundTag":"json-encoding-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}