{"record":{"id":"a3c05a829e681f57","repo":"hasura/graphql-engine","slug":"error-in-executing-pre-response-plugins-unable-to","errorCode":null,"errorMessage":"error in executing pre-response plugins, unable to encode response: {0}","messagePattern":"error in executing pre-response plugins, unable to encode response: (.+?)","errorType":"exception","errorClass":"ExecutePreResponsePluginsError","httpStatus":null,"severity":"error","filePath":"v3/crates/graphql/graphql-ws/src/protocol/subscribe.rs","lineNumber":753,"sourceCode":"                        send_graphql_errors(operation_id, errors, connection).await;\n                        stop_subscription = true;\n                    }\n                }\n            }\n            GraphQLResponseOrCustomResponse::CustomResponse(bytes) => {\n                connection\n                    .send(ws::Message::Raw(axum::extract::ws::Message::Binary(bytes)))\n                    .await;\n            }\n        }\n    }\n    stop_subscription\n}\n\n#[derive(thiserror::Error, Debug)]\n#[error(\"error in executing pre-response plugins, unable to encode response: {0}\")]\nenum ExecutePreResponsePluginsError {\n    #[error(\"error in executing pre-response plugins, unable to encode response: {0}\")]\n    EncodeError(#[from] serde_json::Error),\n    #[error(\"error in executing pre-response plugins: {0}\")]\n    PreResponsePluginError(#[from] pre_response_plugin::Error),\n}\n\nimpl tracing_util::TraceableError for ExecutePreResponsePluginsError {\n    fn visibility(&self) -> tracing_util::ErrorVisibility {\n        tracing_util::ErrorVisibility::User\n    }\n}\n\nasync fn run_pre_response_plugins<M: WebSocketMetrics>(\n    client_address: std::net::SocketAddr,\n    raw_request: &lang_graphql::http::RawRequest,\n    session: Session,\n    headers: http::HeaderMap,\n    response: &lang_graphql::http::Response,\n    connection: &ws::Connection<M>,","sourceCodeStart":735,"sourceCodeEnd":771,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/graphql/graphql-ws/src/protocol/subscribe.rs#L735-L771","documentation":"Raised when a pre-response plugin produced a response that could not be serialized to JSON (`serde_json::Error`), reported via `ExecutePreResponsePluginsError::EncodeError`. After pre-response plugins mutate the response, it must be encoded to JSON for the websocket frame; invalid data (e.g. a map with a non-string key) fails encoding.","triggerScenarios":"A pre-response plugin returns or mutates a response payload containing values serde_json cannot serialize — such as a map with non-string keys, NaN/Infinity floats, or a type without Serialize — during subscription response processing.","commonSituations":"Custom plugin serializing HashMap<NonStringKey, _>; floats becoming NaN through computation; plugin version change introducing a non-serializable field; custom Serialize impl returning an error.","solutions":["Log the serde_json error to find the offending field in the plugin's response","Replace non-serializable constructs (use string keys, handle NaN via arithmetic checks or serde_json 'arbitrary_precision'/'float_roundtrip' features)","Add unit tests serializing the plugin output with serde_json::to_value in CI","Run the plugin chain in a dev environment with representative payloads before deploying"],"exampleFix":"// before (Rust plugin)\nlet meta: HashMap<u32, String> = build_meta();\n// after\nlet meta: BTreeMap<String, String> = build_meta().into_iter().map(|(k,v)|(k.to_string(),v)).collect();","handlingStrategy":"try-catch","validationCode":"// Rust: verify plugin output is JSON-encodable before returning\nserde_json::to_value(&response)?;","typeGuard":null,"tryCatchPattern":"match err { ExecutePreResponsePluginsError::EncodeError(e) => log::error!(\"encode: {e}\"); _ => {} }","preventionTips":["Use string keys in maps and avoid NaN/Infinity in plugin outputs","Unit-test serde_json::to_value on plugin results","Enable serde_json features for precise float handling"],"tags":["graphql-ws","serde-json","serialization","plugins"],"backgroundTag":"json-serialization-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}