Skip to content

Commit 34990c8

Browse files
authored
fix: fixes tools on files not found (#467)
1 parent 6f23567 commit 34990c8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/codegen/extensions/tools/file_operations.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ def view_file(codebase: Codebase, filepath: str) -> dict[str, Any]:
2525
pass
2626

2727
if not file:
28-
for f in codebase.files:
29-
if f.file_path.endswith(filepath):
30-
file = f
31-
break
32-
33-
if not file:
34-
return {"error": f"File not found: {filepath}"}
28+
return {"error": f"File not found: {filepath}. Please use full filepath relative to workspace root."}
3529

3630
return {
3731
"filepath": file.filepath,
@@ -106,6 +100,8 @@ def edit_file(codebase: Codebase, filepath: str, content: str) -> dict[str, Any]
106100
file = codebase.get_file(filepath)
107101
except ValueError:
108102
return {"error": f"File not found: {filepath}"}
103+
if file is None:
104+
return {"error": f"File not found: {filepath}"}
109105

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

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

169169
if codebase.has_file(new_filepath):
170170
return {"error": f"Destination file already exists: {new_filepath}"}
@@ -204,6 +204,8 @@ def move_symbol(
204204
source = codebase.get_file(source_file)
205205
except ValueError:
206206
return {"error": f"Source file not found: {source_file}"}
207+
if source is None:
208+
return {"error": f"Source file not found: {source_file}"}
207209

208210
try:
209211
target = codebase.get_file(target_file)

0 commit comments

Comments
 (0)