mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-27 06:54:59 +00:00
fix: Create parent directories for history files and improve error handling
This commit is contained in:
parent
5b317e5ec0
commit
14af218ea2
1 changed files with 14 additions and 4 deletions
12
aider/io.py
12
aider/io.py
|
@ -308,6 +308,12 @@ class InputOutput:
|
||||||
self.yes = yes
|
self.yes = yes
|
||||||
|
|
||||||
self.input_history_file = input_history_file
|
self.input_history_file = input_history_file
|
||||||
|
if self.input_history_file:
|
||||||
|
try:
|
||||||
|
Path(self.input_history_file).parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
except (PermissionError, OSError) as e:
|
||||||
|
self.tool_warning(f"Could not create directory for input history: {e}")
|
||||||
|
self.input_history_file = None
|
||||||
self.llm_history_file = llm_history_file
|
self.llm_history_file = llm_history_file
|
||||||
if chat_history_file is not None:
|
if chat_history_file is not None:
|
||||||
self.chat_history_file = Path(chat_history_file)
|
self.chat_history_file = Path(chat_history_file)
|
||||||
|
@ -731,7 +737,6 @@ class InputOutput:
|
||||||
if not self.input_history_file:
|
if not self.input_history_file:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
Path(self.input_history_file).parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
FileHistory(self.input_history_file).append_string(inp)
|
FileHistory(self.input_history_file).append_string(inp)
|
||||||
# Also add to the in-memory history if it exists
|
# Also add to the in-memory history if it exists
|
||||||
if self.prompt_session and self.prompt_session.history:
|
if self.prompt_session and self.prompt_session.history:
|
||||||
|
@ -750,9 +755,14 @@ class InputOutput:
|
||||||
if not self.llm_history_file:
|
if not self.llm_history_file:
|
||||||
return
|
return
|
||||||
timestamp = datetime.now().isoformat(timespec="seconds")
|
timestamp = datetime.now().isoformat(timespec="seconds")
|
||||||
|
try:
|
||||||
|
Path(self.llm_history_file).parent.mkdir(parents=True, exist_ok=True)
|
||||||
with open(self.llm_history_file, "a", encoding="utf-8") as log_file:
|
with open(self.llm_history_file, "a", encoding="utf-8") as log_file:
|
||||||
log_file.write(f"{role.upper()} {timestamp}\n")
|
log_file.write(f"{role.upper()} {timestamp}\n")
|
||||||
log_file.write(content + "\n")
|
log_file.write(content + "\n")
|
||||||
|
except (PermissionError, OSError) as err:
|
||||||
|
self.tool_warning(f"Unable to write to llm history file {self.llm_history_file}: {err}")
|
||||||
|
self.llm_history_file = None
|
||||||
|
|
||||||
def display_user_input(self, inp):
|
def display_user_input(self, inp):
|
||||||
if self.pretty and self.user_input_color:
|
if self.pretty and self.user_input_color:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue