From c84072c69163513d548d6dcc76a6c21272acfa87 Mon Sep 17 00:00:00 2001 From: Luke Alvoeiro Date: Mon, 9 Sep 2024 14:00:20 -0700 Subject: [PATCH] fix: remove unsafe pop of messages (#47) --- src/goose/cli/session.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/goose/cli/session.py b/src/goose/cli/session.py index bb705373..600dd82f 100644 --- a/src/goose/cli/session.py +++ b/src/goose/cli/session.py @@ -157,13 +157,13 @@ class Session: except KeyboardInterrupt: self.interrupt_reply() except Exception: + # rewind to right before the last user message + self.exchange.rewind_to_last_user_message() print(traceback.format_exc()) - if self.exchange.messages: - self.exchange.messages.pop() print( "\n[red]The error above was an exception we were not able to handle.\n\n[/]" + "These errors are often related to connection or authentication\n" - + "We've removed your most recent input" + + "We've removed the conversation up to the most recent user message" + " - [yellow]depending on the error you may be able to continue[/]" ) self.notifier.stop()