{"record":{"id":"d36c124b8762c67f","repo":"hasura/graphql-engine","slug":"error-serializing-the-modified-response-0","errorCode":null,"errorMessage":"Error serializing the modified response: {0}","messagePattern":"Error serializing the modified response: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/crates/plugins/pre-response-plugin/src/execute/common.rs","lineNumber":29,"sourceCode":"use reqwest::header::HeaderValue;\nuse serde::Serialize;\nuse tracing_util::{ErrorVisibility, TraceableError};\n\n#[derive(Debug, thiserror::Error)]\npub enum Error {\n    #[error(\"Error while making the HTTP request to the pre-parse plugin {0} - {1}\")]\n    ErrorWhileMakingHTTPRequestToTheHook(String, reqwest::Error),\n    #[error(\"Error while building the request for the pre-parse plugin {0} - {1}\")]\n    BuildRequestError(String, String),\n    #[error(\"Reqwest error: {0}\")]\n    ReqwestError(reqwest::Error),\n    #[error(\"Error parsing the request: {0}\")]\n    PluginRequestParseError(serde_json::Error),\n    #[error(\"Error parsing the engine response: {0}\")]\n    EngineResponseParseError(serde_json::Error),\n    #[error(\"Unexpected status code: {0}\")]\n    UnexpectedStatusCode(u16),\n    #[error(\"Error serializing the modified response: {0}\")]\n    ResponseSerializationError(serde_json::Error),\n    #[error(\"Error while preparing the response: {0}\")]\n    ResponsePreparationError(axum::http::Error),\n}\n\nimpl TraceableError for Error {\n    fn visibility(&self) -> ErrorVisibility {\n        ErrorVisibility::Internal\n    }\n}\n\nimpl Error {\n    pub fn to_graphql_response(self) -> lang_graphql::http::Response {\n        let is_internal = match &self {\n            Error::ErrorWhileMakingHTTPRequestToTheHook(_, _)\n            | Error::UnexpectedStatusCode(_)\n            | Error::ResponseSerializationError(_)\n            | Error::ResponsePreparationError(_) => false,","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/plugins/pre-response-plugin/src/execute/common.rs#L11-L47","documentation":"After the hook mutates the response, the pre-response plugin failed to serialize the modified response back to JSON (serde_json::Error). This happens on the write side, when producing the body to return.","triggerScenarios":"The hook returns response content that cannot round-trip through the engine's response model — e.g. non-serializable values, or a structure that serde rejects on serialize (map with non-string keys, NaN in serde_json strict mode).","commonSituations":"Hook injecting unusual JSON values (NaN/Infinity floats) that serde_json refuses; deeply mutated structures violating the response type.","solutions":["Inspect the modified response produced by the hook for non-serializable values (NaN, Infinity, invalid map keys).","Fix the hook to emit plain, JSON-safe values.","Sanitize/normalize hook output before merging into the response."],"exampleFix":"// before (hook emits NaN)\nlet v = serde_json::json!({ \"score\": f64::NAN });\n\n// after\nlet v = serde_json::json!({ \"score\": null });","handlingStrategy":"validation","validationCode":"// hook side: ensure JSON-safe values before returning\nfn sanitize(v: f64) -> serde_json::Value {\n    if v.is_finite() { v.into() } else { serde_json::Value::Null }\n}","typeGuard":null,"tryCatchPattern":"match serde_json::to_value(&modified) {\n    Ok(v) => v,\n    Err(e) => { tracing::warn!(\"hook produced unserializable response: {e}\"); engine_response_untouched }\n}","preventionTips":["Never emit NaN/Infinity from hooks; use null.","Round-trip test hook output through serde_json in the hook's own tests.","Validate mutated structures against the response model before returning."],"tags":["json","serde","plugin","rust","pre-response-hook"],"backgroundTag":"json-serialization-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}