{"record":{"id":"ca4c890d0ac5ab1c","repo":"zed-industries/zed","slug":"failed-to-serialize-json","errorCode":null,"errorMessage":"failed to serialize JSON","messagePattern":"failed to serialize JSON","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/http_client/src/async_body.rs","lineNumber":99,"sourceCode":"        Self::from_bytes(Bytes::from_static(s))\n    }\n}\n\nimpl From<&'static str> for AsyncBody {\n    #[inline]\n    fn from(s: &'static str) -> Self {\n        Self::from_bytes(Bytes::from_static(s.as_bytes()))\n    }\n}\n\n/// Newtype wrapper that serializes a value as JSON into an `AsyncBody`.\npub struct Json<T: Serialize>(pub T);\n\nimpl<T: Serialize> From<Json<T>> for AsyncBody {\n    fn from(json: Json<T>) -> Self {\n        Self::from_bytes(\n            serde_json::to_vec(&json.0)\n                .expect(\"failed to serialize JSON\")\n                .into(),\n        )\n    }\n}\n\nimpl<T: Into<Self>> From<Option<T>> for AsyncBody {\n    fn from(body: Option<T>) -> Self {\n        match body {\n            Some(body) => body.into(),\n            None => Self::empty(),\n        }\n    }\n}\n\nimpl futures::AsyncRead for AsyncBody {\n    fn poll_read(\n        self: Pin<&mut Self>,\n        cx: &mut std::task::Context<'_>,","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/http_client/src/async_body.rs#L81-L117","documentation":"Panics inside From<Json<T>> for AsyncBody when serde_json::to_vec fails to serialize the wrapped T. Because serde_json's Serializer is infallible for virtually all types (it errors only on maps/keys that are not strings or on disabled features), this effectively only fires when T's Serialize impl itself errors — i.e., a custom Serialize implementation returning an Err.","triggerScenarios":"Thrown at crates/http_client/src/async_body.rs:99 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Audit the custom Serialize impl of the wrapped type T for error-returning paths","Switch the conversion to return a Result (e.g., serde_json::to_vec(...).map_err(...) into anyhow) so callers can propagate the failure","Add a unit test serializing the concrete type to catch regressions in its Serialize impl"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}