{"record":{"id":"86494846ed83be56","repo":"BoundaryML/baml","slug":"failed-to-get-text-from-http-body-e","errorCode":null,"errorMessage":"Failed to get text from HTTP body:\n{e:?}","messagePattern":"Failed to get text from HTTP body:\n(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"engine/language_client_ruby/ext/ruby_ffi/src/types/request.rs","lineNumber":82,"sourceCode":"    }\n}\n\nimpl HTTPBody {\n    pub fn raw(ruby: &Ruby, rb_self: &Self) -> Result<TypedArray<u8>> {\n        let array = ruby.typed_ary_new();\n\n        // TODO: Can we avoid cloning or at least do this faster than byte by\n        // byte?\n        for byte in rb_self.inner.raw() {\n            array.push(*byte)?;\n        }\n\n        Ok(array)\n    }\n\n    pub fn text(ruby: &Ruby, rb_self: &Self) -> Result<String> {\n        rb_self.inner.text().map(String::from).map_err(|e| {\n            Error::new(\n                ruby.exception_runtime_error(),\n                format!(\"Failed to get text from HTTP body:\\n{e:?}\"),\n            )\n        })\n    }\n\n    pub fn json(ruby: &Ruby, rb_self: &Self) -> Result<magnus::Value> {\n        serde_magnus::serialize(&rb_self.inner.json().map_err(|e| {\n            Error::new(\n                ruby.exception_runtime_error(),\n                format!(\"Failed deserializing HTTP body as JSON:\\n{e:?}\"),\n            )\n        })?)\n    }\n\n    pub fn define_in_ruby(module: &RModule) -> Result<()> {\n        let cls = module.define_class(\"HTTPBody\", class::object())?;\n","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_ruby/ext/ruby_ffi/src/types/request.rs#L64-L100","documentation":"HTTPBody#text reads the request/response body as a UTF-8 string. If the underlying body cannot yield text (e.g. reading fails or bytes are not valid text per the http crate), a Ruby RuntimeError with 'Failed to get text from HTTP body' plus the debug error is raised.","triggerScenarios":"Calling text on an HTTPBody whose stream is already consumed, aborted, or whose bytes fail text conversion.","commonSituations":"Reading a body twice (body already drained by an earlier text/json call), streaming responses interrupted mid-read, or binary bodies.","solutions":["Read the body exactly once; cache the result if you need it multiple times.","Use bytes/binary access instead of text for non-UTF8 payloads.","Check response status before reading; error bodies may be abnormal."],"exampleFix":"// before\nbody = request.body\na = body.text\nb = body.text # fails: body already consumed\n// after\nbody = request.body\ntext = body.text\na = text\nb = text","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  text = request.body.text\nrescue RuntimeError => e\n  text = nil\nend","preventionTips":["Read each body exactly once and cache the result.","Use binary access for non-text payloads."],"tags":["ruby","ffi","http-body"],"backgroundTag":"file-read-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}