{"record":{"id":"c268702dc036d91e","repo":"ent/ent","slug":"gremlin-http-decoding-response-w","errorCode":null,"errorMessage":"gremlin/http: decoding response: %w","messagePattern":"gremlin/http: decoding response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dialect/gremlin/http.go","lineNumber":82,"sourceCode":"\t\trsp, err := t.client.Do(req.WithContext(ctx))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"gremlin/http: posting http request: %w\", err)\n\t\t}\n\t\tdefer rsp.Body.Close()\n\n\t\tif rsp.StatusCode < http.StatusOK || rsp.StatusCode > http.StatusPartialContent {\n\t\t\tbody, _ := io.ReadAll(rsp.Body)\n\t\t\treturn nil, fmt.Errorf(\"gremlin/http: status=%q, body=%q\", rsp.Status, body)\n\t\t}\n\t\tif rsp.ContentLength > MaxResponseSize {\n\t\t\treturn nil, errors.New(\"gremlin/http: context length exceeds limit\")\n\t\t}\n\t\tbr = rsp.Body\n\t}\n\n\tvar rsp Response\n\tif err := graphson.NewDecoder(io.LimitReader(br, MaxResponseSize)).Decode(&rsp); err != nil {\n\t\treturn nil, fmt.Errorf(\"gremlin/http: decoding response: %w\", err)\n\t}\n\treturn &rsp, nil\n}\n","sourceCodeStart":64,"sourceCodeEnd":86,"githubUrl":"https://github.com/ent/ent/blob/69d5d4deb19599f129166634e09d33addcf3f2cc/dialect/gremlin/http.go#L64-L86","documentation":"This error is returned by the Gremlin HTTP transport's RoundTrip when the response body cannot be decoded as GraphSON into the library's Response struct. It wraps the underlying graphson decoder error, which typically indicates the server sent HTML (an error page), JSON in an unexpected shape, an unsupported GraphSON version, or truncated output (also guarded by MaxResponseSize).","triggerScenarios":"Decoding the response body via graphson.NewDecoder(io.LimitReader(br, MaxResponseSize)).Decode(&rsp) fails: body is HTML/plain text (proxy or error page), GraphSON version mismatch (GraphSONv1 vs v3), malformed JSON from a proxy intercepting traffic, or body exceeds MaxResponseSize and is truncated.","commonSituations":"Reverse proxy or load balancer returning an HTML 502 page; Gremlin server configured with a serializer (GraphSONv1) unsupported by the client's decoder; middleware (WAF) altering the response; response larger than MaxResponseSize cut off mid-stream by the LimitReader.","solutions":["Inspect the raw response body (e.g. with a debug http.Client RoundTripper) to see what the server actually returned.","Check the Gremlin server serializer configuration — set GraphSONv3 (org.apache.tinkerpop.gremlin.util.ser.GraphSONMessageSerializerV3) to match what the client expects.","If the body is HTML, look for a proxy/load balancer between the client and Gremlin and bypass or fix it.","If the traversal returns very large result sets, reduce result size (limit(), pagination) so the response fits within MaxResponseSize."],"exampleFix":"// before: server uses GraphSONv1, client fails to decode\n// gremlin-server.yaml: GraphSONMessageSerializerV1d\n// after: configure server serializer to GraphSON v3\n// gremlin-server.yaml:\n//   serializers:\n//     - className: org.apache.tinkerpop.gremlin.util.ser.GraphSONMessageSerializerV3","handlingStrategy":"validation","validationCode":"// verify the server speaks GraphSON the client understands before dialing\nresp, err := http.Post(uri, \"application/json\", strings.NewReader(`{\"requestId\":\"test\",\"opName\":\"\"}`))\nif err == nil {\n    b, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))\n    resp.Body.Close()\n    if !json.Valid(b) && strings.Contains(string(b), \"<html\") {\n        return errors.New(\"gremlin endpoint returned HTML, not GraphSON — check proxy/serializer\")\n    }\n}","typeGuard":null,"tryCatchPattern":"r, err := client.Exec(ctx, g.V())\nif err != nil {\n    if strings.Contains(err.Error(), \"decoding response\") {\n        // capture body via a debug RoundTripper and inspect raw payload\n        return fmt.Errorf(\"non-GraphSON response, check proxy/serializer: %w\", err)\n    }\n    return err\n}","preventionTips":["Configure the Gremlin server with GraphSON v3 serializer matching the client.","Ensure no proxy/WAF sits between client and server rewriting responses.","Keep result sets under MaxResponseSize (use limit()/pagination for big traversals).","Add a debug HTTP RoundTripper in dev to log raw responses."],"tags":["gremlin","http","serialization","decoding"],"backgroundTag":"response-decoding-failed","analyzedSha":"69d5d4deb19599f129166634e09d33addcf3f2cc","analyzedAt":"2026-09-03T16:51:39.799Z","contentChangedAt":"2026-09-03T16:51:39.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}