Skip to content

fix: fixes tools on files not found #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/codegen/extensions/tools/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ def view_file(codebase: Codebase, filepath: str) -> dict[str, Any]:
pass

if not file:
for f in codebase.files:
if f.file_path.endswith(filepath):
file = f
break

if not file:
return {"error": f"File not found: {filepath}"}
return {"error": f"File not found: {filepath}. Please use full filepath relative to workspace root."}

return {
"filepath": file.filepath,
Expand Down Expand Up @@ -106,6 +100,8 @@ def edit_file(codebase: Codebase, filepath: str, content: str) -> dict[str, Any]
file = codebase.get_file(filepath)
except ValueError:
return {"error": f"File not found: {filepath}"}
if file is None:
return {"error": f"File not found: {filepath}"}

file.edit(content)
codebase.commit()
Expand Down Expand Up @@ -144,6 +140,8 @@ def delete_file(codebase: Codebase, filepath: str) -> dict[str, Any]:
file = codebase.get_file(filepath)
except ValueError:
return {"error": f"File not found: {filepath}"}
if file is None:
return {"error": f"File not found: {filepath}"}

file.remove()
codebase.commit()
Expand All @@ -165,6 +163,8 @@ def rename_file(codebase: Codebase, filepath: str, new_filepath: str) -> dict[st
file = codebase.get_file(filepath)
except ValueError:
return {"error": f"File not found: {filepath}"}
if file is None:
return {"error": f"File not found: {filepath}"}

if codebase.has_file(new_filepath):
return {"error": f"Destination file already exists: {new_filepath}"}
Expand Down Expand Up @@ -204,6 +204,8 @@ def move_symbol(
source = codebase.get_file(source_file)
except ValueError:
return {"error": f"Source file not found: {source_file}"}
if source is None:
return {"error": f"Source file not found: {source_file}"}

try:
target = codebase.get_file(target_file)
Expand Down