BoundaryML/baml · error · RuntimeError
{e:?}
Error message
{e:?} What it means
Raised by LogCollector (or its inner type) into_value when serde_magnus::serialize fails to turn the collector's inner Rust struct into a Ruby Value. The raw serde error is debug-formatted as the message of a Ruby RuntimeError. This means the log collector object could not be exposed to Ruby.
Source
Thrown at engine/language_client_ruby/ext/ruby_ffi/src/types/log_collector.rs:367
}
pub fn duration_ms(&self) -> Option<i64> {
self.inner.duration_ms
}
pub fn define_in_ruby(module: &RModule) -> Result<()> {
let cls = module.define_class("Timing", class::object())?;
cls.define_method("to_s", method!(Timing::to_s, 0))?;
cls.define_method("start_time_utc_ms", method!(Timing::start_time_utc_ms, 0))?;
cls.define_method("duration_ms", method!(Timing::duration_ms, 0))?;
Ok(())
}
pub fn into_value(self, ruby: &Ruby) -> crate::Result<Value> {
serde_magnus::serialize(&self.inner)
.map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e:?}")))
}
}
impl StreamTiming {
pub fn to_s(&self) -> String {
format!(
"StreamTiming(start_time_utc_ms={}, duration_ms={})",
self.inner.start_time_utc_ms,
self.inner
.duration_ms
.map_or("null".to_string(), |v| v.to_string())
)
}
pub fn start_time_utc_ms(&self) -> i64 {
self.inner.start_time_utc_ms
}
View on GitHub (pinned to bd85ce9dee)
Solutions
- Read the {e:?} payload for the exact field/serde failure.
- Rebuild the native extension (gem pristine baml) to remove Rust/Ruby version mismatch.
- Upgrade to the latest baml gem; collector serialization bugs are fixed periodically.
- As a workaround, access collected data through collector logs/usage methods instead of the raw serialized object.
Defensive patterns
Strategy: try-catch
Validate before calling
raise 'native extension stale' unless File.exist?(Baml::Ffi.method(:new_collector).source_location rescue true)
Type guard
def collector_usable?(collector) collector.respond_to?(:into_value) || collector.respond_to?(:logs) rescue StandardError false end
Try / catch
begin
value = collector.into_value
rescue RuntimeError => e
logger.warn("collector serialization failed: #{e.message}; using logs API")
value = collector.logs
end Prevention
- Rebuild the native extension after any baml gem upgrade.
- Use the collector's typed accessor methods instead of raw serialization where possible.
- Keep the baml gem at the latest patch version.
- Guard collector retrieval code so a serialization failure doesn't crash response handling.
When it happens
Trigger: Calling into_value on a LogCollector whose inner state contains data serde_magnus cannot map to Ruby (unexpected value shapes, incompatible baml version mixing), typically when retrieving a collector after function calls complete.
Common situations: Fetching collectors via Baml::Ffi after a streaming call where internal state holds a variant serde_magnus doesn't support; stale native extension after gem upgrade causing serde mismatches.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- JSON serialization error: {0}
- Failed to serialize request result: {0}
- error while parsing call_function args: {e}
- error while parsing stream_function args: {e}
- failed coercing BAML value to Ruby value: {e:?}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/a26c8c7ca75a2434.
Report an issue: GitHub.