BoundaryML/baml · error · RuntimeError
Failed to get text from HTTP body: {e:?}
Error message
Failed to get text from HTTP body:
{e:?} What it means
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.
Source
Thrown at engine/language_client_ruby/ext/ruby_ffi/src/types/request.rs:82
}
}
impl HTTPBody {
pub fn raw(ruby: &Ruby, rb_self: &Self) -> Result<TypedArray<u8>> {
let array = ruby.typed_ary_new();
// TODO: Can we avoid cloning or at least do this faster than byte by
// byte?
for byte in rb_self.inner.raw() {
array.push(*byte)?;
}
Ok(array)
}
pub fn text(ruby: &Ruby, rb_self: &Self) -> Result<String> {
rb_self.inner.text().map(String::from).map_err(|e| {
Error::new(
ruby.exception_runtime_error(),
format!("Failed to get text from HTTP body:\n{e:?}"),
)
})
}
pub fn json(ruby: &Ruby, rb_self: &Self) -> Result<magnus::Value> {
serde_magnus::serialize(&rb_self.inner.json().map_err(|e| {
Error::new(
ruby.exception_runtime_error(),
format!("Failed deserializing HTTP body as JSON:\n{e:?}"),
)
})?)
}
pub fn define_in_ruby(module: &RModule) -> Result<()> {
let cls = module.define_class("HTTPBody", class::object())?;
View on GitHub (pinned to bd85ce9dee)
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.
Example fix
// before body = request.body a = body.text b = body.text # fails: body already consumed // after body = request.body text = body.text a = text b = text
Defensive patterns
Strategy: try-catch
Try / catch
begin text = request.body.text rescue RuntimeError => e text = nil end
Prevention
- Read each body exactly once and cache the result.
- Use binary access for non-text payloads.
When it happens
Trigger: Calling text on an HTTPBody whose stream is already consumed, aborted, or whose bytes fail text conversion.
Common situations: Reading a body twice (body already drained by an earlier text/json call), streaming responses interrupted mid-read, or binary bodies.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Failed deserializing HTTP body as JSON: {e:?}
- No LLM response: {}
- failing inside parsed_using_types: {e:?}
- Failed to parse LLM response: {}
- {e:?}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/86494846ed83be56.
Report an issue: GitHub.