diff options
| author | Tommaso Sciortino <[email protected]> | 2025-08-20 16:13:29 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-20 23:13:29 +0000 |
| commit | 0193ce77dd0f4db5cd3822d3eb54c6f41a816253 (patch) | |
| tree | 3f2c879060413b30cddbf51ff19859f07500983b /packages/core/src/tools | |
| parent | 6eb6560d4204ebcc086245be7336a1bcc21c5f04 (diff) | |
Remove unnecessary FileErrorType. (#6697)
Diffstat (limited to 'packages/core/src/tools')
| -rw-r--r-- | packages/core/src/tools/read-file.test.ts | 2 | ||||
| -rw-r--r-- | packages/core/src/tools/read-file.ts | 38 | ||||
| -rw-r--r-- | packages/core/src/tools/read-many-files.ts | 5 |
3 files changed, 6 insertions, 39 deletions
diff --git a/packages/core/src/tools/read-file.test.ts b/packages/core/src/tools/read-file.test.ts index 82958184..7f7f5ede 100644 --- a/packages/core/src/tools/read-file.test.ts +++ b/packages/core/src/tools/read-file.test.ts @@ -219,7 +219,7 @@ describe('ReadFileTool', () => { returnDisplay: 'Path is a directory.', error: { message: `Path is a directory, not a file: ${dirPath}`, - type: ToolErrorType.INVALID_TOOL_PARAMS, + type: ToolErrorType.TARGET_IS_DIRECTORY, }, }); }); diff --git a/packages/core/src/tools/read-file.ts b/packages/core/src/tools/read-file.ts index da8a004d..7e9e8535 100644 --- a/packages/core/src/tools/read-file.ts +++ b/packages/core/src/tools/read-file.ts @@ -14,7 +14,7 @@ import { ToolLocation, ToolResult, } from './tools.js'; -import { ToolErrorType } from './tool-error.js'; + import { PartUnion } from '@google/genai'; import { processSingleFileContent, @@ -79,44 +79,12 @@ class ReadFileToolInvocation extends BaseToolInvocation< ); if (result.error) { - // Map error messages to ToolErrorType - let errorType: ToolErrorType; - let llmContent: string; - - // Check error message patterns to determine error type - if ( - result.error.includes('File not found') || - result.error.includes('does not exist') || - result.error.includes('ENOENT') - ) { - errorType = ToolErrorType.FILE_NOT_FOUND; - llmContent = - 'Could not read file because no file was found at the specified path.'; - } else if ( - result.error.includes('is a directory') || - result.error.includes('EISDIR') - ) { - errorType = ToolErrorType.INVALID_TOOL_PARAMS; - llmContent = - 'Could not read file because the provided path is a directory, not a file.'; - } else if ( - result.error.includes('too large') || - result.error.includes('File size exceeds') - ) { - errorType = ToolErrorType.FILE_TOO_LARGE; - llmContent = `Could not read file. ${result.error}`; - } else { - // Other read errors map to READ_CONTENT_FAILURE - errorType = ToolErrorType.READ_CONTENT_FAILURE; - llmContent = `Could not read file. ${result.error}`; - } - return { - llmContent, + llmContent: result.llmContent, returnDisplay: result.returnDisplay || 'Error reading file', error: { message: result.error, - type: errorType, + type: result.errorType, }, }; } diff --git a/packages/core/src/tools/read-many-files.ts b/packages/core/src/tools/read-many-files.ts index 52529ce9..b3568cad 100644 --- a/packages/core/src/tools/read-many-files.ts +++ b/packages/core/src/tools/read-many-files.ts @@ -21,6 +21,7 @@ import { processSingleFileContent, DEFAULT_ENCODING, getSpecificMimeType, + ProcessedFileReadResult, } from '../utils/fileUtils.js'; import { PartListUnion } from '@google/genai'; import { Config, DEFAULT_FILE_FILTERING_OPTIONS } from '../config/config.js'; @@ -84,9 +85,7 @@ type FileProcessingResult = success: true; filePath: string; relativePathForDisplay: string; - fileReadResult: NonNullable< - Awaited<ReturnType<typeof processSingleFileContent>> - >; + fileReadResult: ProcessedFileReadResult; reason?: undefined; } | { |
