{"record":{"id":"760022639e33617b","repo":"BoundaryML/baml","slug":"e-function-result-stream","errorCode":null,"errorMessage":"{e:?}","messagePattern":"\\{e:\\?\\}","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"engine/language_client_ruby/ext/ruby_ffi/src/function_result_stream.rs","lineNumber":49,"sourceCode":"            let proc = ruby.block_proc()?;\n            Some(move |event: baml_runtime::FunctionResult| {\n                // ignore errors if they happen\n                let _ = proc.call::<_, magnus::Value>((FunctionResult::new(event),));\n            })\n        } else {\n            None\n        };\n\n        match rb_self.t.block_on(rb_self.inner.borrow_mut().run(\n            None::<fn()>,\n            on_event,\n            &ctx.inner,\n            None,\n            None,\n            HashMap::new(),\n        )) {\n            (Ok(res), _) => Ok(FunctionResult::new(res)),\n            (Err(e), _) => Err(Error::new(ruby.exception_runtime_error(), format!(\"{e:?}\"))),\n        }\n    }\n\n    /// For usage in magnus::init\n    ///\n    /// TODO: use traits and macros to implement this\n    pub fn define_in_ruby(module: &RModule) -> Result<()> {\n        let cls = module.define_class(\"FunctionResultStream\", class::object())?;\n\n        cls.define_method(\"done\", method!(FunctionResultStream::done, 1))?;\n\n        Ok(())\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":64,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_ruby/ext/ruby_ffi/src/function_result_stream.rs#L31-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"Streaming calls that die mid-flight due to connectivity issues, exhausted retries, or invalid API keys surfaced only at done() time.","solutions":["Read the {e:?} detail to identify the underlying provider error","Wrap .done in begin/rescue RuntimeError and retry the stream","Configure retry/fallback strategies on the BAML client","Check API key validity and network stability for streaming"],"exampleFix":"// before\nfinal = stream.done\n// after\nfinal =\n  begin\n    stream.done\n  rescue RuntimeError => e\n    warn \"Stream failed: #{e.message}\"\n    nil\n  end","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  final = stream.done\nrescue RuntimeError => e\n  logger.error(\"stream failed: #{e.message}\")\n  final = retry_stream_once\nend","preventionTips":["Wrap stream.finalize/done in retry logic","Verify API keys and network before long streams","Use BAML retry policies so transient stream errors self-heal"],"tags":["ruby","ffi","streaming"],"backgroundTag":"stream-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"}