Skip to content

Commit 1016ed2

Browse files
authored
fix: allow user to retry on non-client error (#661)
* fix: allow user to retry on non-client error * fix: format * fix: adds condition to remove last exchange in history
1 parent 2766951 commit 1016ed2

File tree

1 file changed

+55
-5
lines changed
  • crates/q_cli/src/cli/chat

1 file changed

+55
-5
lines changed

crates/q_cli/src/cli/chat/mod.rs

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,37 @@ Hi, I'm <g>Amazon Q</g>. Ask me anything.
221221
}
222222

223223
loop {
224-
let mut response = self.prompt_and_send_request().await?;
224+
let mut response = loop {
225+
match self.prompt_and_send_request().await {
226+
Ok(resp) => {
227+
break resp;
228+
},
229+
Err(e) => {
230+
if self.is_interactive && self.spinner.is_some() {
231+
drop(self.spinner.take());
232+
queue!(
233+
self.output,
234+
terminal::Clear(terminal::ClearType::CurrentLine),
235+
cursor::MoveToColumn(0),
236+
cursor::Show
237+
)?;
238+
}
239+
execute!(
240+
self.output,
241+
style::SetAttribute(Attribute::Bold),
242+
style::SetForegroundColor(Color::Red),
243+
style::Print(format!("Amazon Q is having trouble responding right now: {:?}\n", e)),
244+
style::Print("Please try again later.\n"),
245+
style::SetForegroundColor(Color::Reset),
246+
style::SetAttribute(Attribute::Reset),
247+
)?;
248+
if self.conversation_state.next_message.is_none() {
249+
self.conversation_state.history.pop_back();
250+
}
251+
continue;
252+
},
253+
}
254+
};
225255
let response = match response.take() {
226256
Some(response) => response,
227257
None => {
@@ -274,10 +304,30 @@ Hi, I'm <g>Amazon Q</g>. Ask me anything.
274304
};
275305
},
276306
Err(err) => {
277-
bail!(
278-
"We're having trouble responding right now, please try again later: {:?}",
279-
err
280-
);
307+
if self.is_interactive && self.spinner.is_some() {
308+
drop(self.spinner.take());
309+
queue!(
310+
self.output,
311+
terminal::Clear(terminal::ClearType::CurrentLine),
312+
cursor::MoveToColumn(0),
313+
cursor::Show
314+
)?;
315+
}
316+
execute!(
317+
self.output,
318+
style::SetAttribute(Attribute::Bold),
319+
style::SetForegroundColor(Color::Red),
320+
style::Print(format!(
321+
"We're having trouble responding right now, please try again later: {:?}",
322+
err
323+
)),
324+
style::SetForegroundColor(Color::Reset),
325+
style::SetAttribute(Attribute::Reset),
326+
)?;
327+
if self.conversation_state.next_message.is_none() {
328+
self.conversation_state.history.pop_back();
329+
}
330+
break;
281331
},
282332
}
283333

0 commit comments

Comments
 (0)