mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 01:35:00 +00:00
refactor: improve file handling and error reporting in Coder class
This commit is contained in:
parent
b6b4fc6fab
commit
01964ca294
2 changed files with 17 additions and 12 deletions
|
@ -349,20 +349,23 @@ class Coder:
|
|||
|
||||
for fname in fnames:
|
||||
fname = Path(fname)
|
||||
if not fname.exists():
|
||||
self.io.tool_output(f"Creating empty file {fname}")
|
||||
fname.parent.mkdir(parents=True, exist_ok=True)
|
||||
utils.touch_file(fname)
|
||||
|
||||
if not fname.is_file():
|
||||
raise ValueError(f"{fname} is not a file")
|
||||
|
||||
fname = str(fname.resolve())
|
||||
|
||||
if self.repo and self.repo.ignored_file(fname):
|
||||
self.io.tool_error(f"Skipping {fname} that matches aiderignore spec.")
|
||||
continue
|
||||
|
||||
if not fname.exists():
|
||||
if utils.touch_file(fname):
|
||||
self.io.tool_output(f"Creating empty file {fname}")
|
||||
else:
|
||||
self.io.tool_error(f"Can not create {fname}, skipping.")
|
||||
continue
|
||||
|
||||
if not fname.is_file():
|
||||
self.io.tool_error(f"Skipping {fname} that is not a normal file.")
|
||||
continue
|
||||
|
||||
fname = str(fname.resolve())
|
||||
|
||||
self.abs_fnames.add(fname)
|
||||
self.check_added_files()
|
||||
|
||||
|
@ -1677,8 +1680,9 @@ class Coder:
|
|||
return
|
||||
|
||||
if not self.dry_run:
|
||||
Path(full_path).parent.mkdir(parents=True, exist_ok=True)
|
||||
utils.touch_file(Path(full_path))
|
||||
if not utils.touch_file(full_path):
|
||||
self.io.tool_error(f"Unable to create {path}, skipping edits.")
|
||||
return
|
||||
|
||||
# Seems unlikely that we needed to create the file, but it was
|
||||
# actually already part of the repo.
|
||||
|
|
|
@ -292,6 +292,7 @@ def format_tokens(count):
|
|||
|
||||
|
||||
def touch_file(fname):
|
||||
fname = Path(fname)
|
||||
try:
|
||||
fname.parent.mkdir(parents=True, exist_ok=True)
|
||||
fname.touch()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue