Skip to content

Commit dfb096a

Browse files
committed
Update trait definition for MaybeError
1 parent 30e5c35 commit dfb096a

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

lib/llm/src/protocols/common/llm_backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ impl LLMEngineOutput {
136136
}
137137

138138
impl MaybeError for LLMEngineOutput {
139-
fn from_err(err: Box<dyn std::error::Error>) -> Self {
139+
fn from_err(err: Box<dyn std::error::Error + Send + Sync>) -> Self {
140140
LLMEngineOutput::error(format!("{:?}", err))
141141
}
142142

143-
fn err(&self) -> Option<Box<dyn std::error::Error>> {
143+
fn err(&self) -> Option<Box<dyn std::error::Error + Send + Sync>> {
144144
if let Some(FinishReason::Error(err_msg)) = &self.finish_reason {
145145
Some(anyhow::Error::msg(err_msg.clone()).into())
146146
} else {

lib/runtime/src/pipeline/network/egress/push_router.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,13 @@ where
196196
let engine_ctx = stream.context();
197197
let client = self.client.clone();
198198
let stream = stream.then(move |res| {
199-
let mut report_instance_down: Option<(Client, i64)> = None;
200-
if let Some(err) = res.err() {
201-
const STREAM_ERR_MSG: &str = "Stream ended before generation completed";
202-
if format!("{:?}", err) == STREAM_ERR_MSG {
203-
report_instance_down = Some((client.clone(), instance_id));
204-
}
205-
}
199+
let client = client.clone();
206200
async move {
207-
if let Some((client, instance_id)) = report_instance_down {
208-
client.report_instance_down(instance_id).await;
201+
if let Some(err) = res.err() {
202+
const STREAM_ERR_MSG: &str = "Stream ended before generation completed";
203+
if format!("{:?}", err) == STREAM_ERR_MSG {
204+
client.report_instance_down(instance_id).await;
205+
}
209206
}
210207
res
211208
}

lib/runtime/src/protocols/annotated.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ impl<R> MaybeError for Annotated<R>
151151
where
152152
R: for<'de> Deserialize<'de> + Serialize,
153153
{
154-
fn from_err(err: Box<dyn std::error::Error>) -> Self {
154+
fn from_err(err: Box<dyn std::error::Error + Send + Sync>) -> Self {
155155
Annotated::from_error(format!("{:?}", err))
156156
}
157157

158-
fn err(&self) -> Option<Box<dyn std::error::Error>> {
158+
fn err(&self) -> Option<Box<dyn std::error::Error + Send + Sync>> {
159159
if self.is_error() {
160160
if let Some(comment) = &self.comment {
161161
if !comment.is_empty() {

lib/runtime/src/protocols/maybe_error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ use std::error::Error;
1717

1818
pub trait MaybeError {
1919
/// Construct an instance from an error.
20-
fn from_err(err: Box<dyn Error>) -> Self;
20+
fn from_err(err: Box<dyn Error + Send + Sync>) -> Self;
2121

2222
/// Construct into an error instance.
23-
fn err(&self) -> Option<Box<dyn Error>>;
23+
fn err(&self) -> Option<Box<dyn Error + Send + Sync>>;
2424

2525
/// Check if the current instance represents a success.
2626
fn is_ok(&self) -> bool {
@@ -41,12 +41,12 @@ mod tests {
4141
message: String,
4242
}
4343
impl MaybeError for TestError {
44-
fn from_err(err: Box<dyn Error>) -> Self {
44+
fn from_err(err: Box<dyn Error + Send + Sync>) -> Self {
4545
TestError {
4646
message: err.to_string(),
4747
}
4848
}
49-
fn err(&self) -> Option<Box<dyn Error>> {
49+
fn err(&self) -> Option<Box<dyn Error + Send + Sync>> {
5050
Some(anyhow::Error::msg(self.message.clone()).into())
5151
}
5252
}

0 commit comments

Comments
 (0)