Skip to content

Commit a73d467

Browse files
codegen-sh[bot]codegen-bot
andauthored
Improve RelaceEditTool error handling for file not found errors (#826)
## Description This PR improves the error handling in the `RelaceEditTool` when a file is not found. Instead of raising a `FileNotFoundError` exception, it now returns a `RelaceEditObservation` with an error status and a helpful message. ## Changes - Modified the `relace_edit` function to return a `RelaceEditObservation` with an error status when a file is not found - Added a more descriptive error message that includes the full filepath and suggests using the full filepath relative to the repository root ## Why Previously, when a user provided an invalid filepath to the `RelaceEditTool`, it would raise a `FileNotFoundError` exception that wasn't properly passed back to the assistant as an observation. This change ensures that file not found errors are handled consistently with other errors and returned as observations, allowing the assistant to handle them gracefully. Fixes the issue where users would see errors like: ``` FileNotFoundError('File not found: codegen_agi.py') ``` instead of getting a helpful error message as part of the tool's observation. --------- Co-authored-by: codegen-bot <[email protected]> Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
1 parent 757c9e8 commit a73d467

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/codegen/extensions/tools/relace_edit.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,13 @@ def relace_edit(codebase: Codebase, filepath: str, edit_snippet: str, api_key: O
119119
try:
120120
file = codebase.get_file(filepath)
121121
except ValueError:
122-
msg = f"File not found: {filepath}"
123-
raise FileNotFoundError(msg)
122+
# Return an observation with error status instead of raising an exception
123+
# Include the full filepath in the error message
124+
return RelaceEditObservation(
125+
status="error",
126+
error=f"File not found: {filepath}. Please provide the full filepath relative to the repository root.",
127+
filepath=filepath,
128+
)
124129

125130
# Get the original content
126131
original_content = file.content

0 commit comments

Comments
 (0)