BoundaryML/baml · error · RuntimeError

{e:?}

Error message

{e:?}

What it means

FunctionResultStream#done finalizes a stream and produces the complete FunctionResult. If the underlying Rust call returns Err, the error is formatted with {e:?} and raised as a Ruby RuntimeError — so the message is the debug dump of the internal failure.

Source

Thrown at engine/language_client_ruby/ext/ruby_ffi/src/function_result_stream.rs:49

            let proc = ruby.block_proc()?;
            Some(move |event: baml_runtime::FunctionResult| {
                // ignore errors if they happen
                let _ = proc.call::<_, magnus::Value>((FunctionResult::new(event),));
            })
        } else {
            None
        };

        match rb_self.t.block_on(rb_self.inner.borrow_mut().run(
            None::<fn()>,
            on_event,
            &ctx.inner,
            None,
            None,
            HashMap::new(),
        )) {
            (Ok(res), _) => Ok(FunctionResult::new(res)),
            (Err(e), _) => Err(Error::new(ruby.exception_runtime_error(), format!("{e:?}"))),
        }
    }

    /// For usage in magnus::init
    ///
    /// TODO: use traits and macros to implement this
    pub fn define_in_ruby(module: &RModule) -> Result<()> {
        let cls = module.define_class("FunctionResultStream", class::object())?;

        cls.define_method("done", method!(FunctionResultStream::done, 1))?;

        Ok(())
    }
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the {e:?} detail to identify the underlying provider error
  2. Wrap .done in begin/rescue RuntimeError and retry the stream
  3. Configure retry/fallback strategies on the BAML client
  4. Check API key validity and network stability for streaming

Example fix

// before
final = stream.done
// after
final =
  begin
    stream.done
  rescue RuntimeError => e
    warn "Stream failed: #{e.message}"
    nil
  end
Defensive patterns

Strategy: retry

Try / catch

begin
  final = stream.done
rescue RuntimeError => e
  logger.error("stream failed: #{e.message}")
  final = retry_stream_once
end

Prevention

When it happens

Trigger: Calling .done on a stream after the LLM request failed (network error, provider 4xx/5xx, cancelled stream), or when aggregate parsing of accumulated partials fails.

Common situations: Streaming calls that die mid-flight due to connectivity issues, exhausted retries, or invalid API keys surfaced only at done() time.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/760022639e33617b. Report an issue: GitHub.