summaryrefslogtreecommitdiffstats
path: root/src/repl/handler.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-03-08 16:06:24 +0800
committersigoden <sigoden@gmail.com>2023-03-08 16:06:24 +0800
commit2a7a6f5f27ae6343c1aa235563cbddb6cb40f557 (patch)
tree1ab01b81d26a5c2a820063e0700ae69781d15440 /src/repl/handler.rs
parent4e729db237dbfb93d32bfa43b60a09be07d49630 (diff)
downloadaichat-2a7a6f5f27ae6343c1aa235563cbddb6cb40f557.tar.gz
chore: no longer ignore any error
Diffstat (limited to 'src/repl/handler.rs')
-rw-r--r--src/repl/handler.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/repl/handler.rs b/src/repl/handler.rs
index 5959cd6..59c8af5 100644
--- a/src/repl/handler.rs
+++ b/src/repl/handler.rs
@@ -3,7 +3,7 @@ use crate::config::SharedConfig;
use crate::print_now;
use crate::render::render_stream;
-use anyhow::Result;
+use anyhow::{Context, Result};
use crossbeam::channel::Sender;
use crossbeam::sync::WaitGroup;
use std::cell::RefCell;
@@ -110,22 +110,25 @@ impl ReplyStreamHandler {
}
}
- pub fn text(&mut self, text: &str) {
+ pub fn text(&mut self, text: &str) -> Result<()> {
match self.sender.as_ref() {
Some(tx) => {
- let _ = tx.send(ReplyStreamEvent::Text(text.to_string()));
+ tx.send(ReplyStreamEvent::Text(text.to_string()))
+ .with_context(|| "Failed to send StreamEvent:Text")?;
}
None => {
print_now!("{}", text);
}
}
self.buffer.push_str(text);
+ Ok(())
}
- pub fn done(&mut self) {
+ pub fn done(&mut self) -> Result<()> {
match self.sender.as_ref() {
Some(tx) => {
- let _ = tx.send(ReplyStreamEvent::Done);
+ tx.send(ReplyStreamEvent::Done)
+ .with_context(|| "Failed to send StreamEvent:Done")?;
}
None => {
if !self.buffer.ends_with('\n') {
@@ -133,6 +136,7 @@ impl ReplyStreamHandler {
}
}
}
+ Ok(())
}
pub fn get_buffer(&self) -> &str {