diff options
Diffstat (limited to 'packages/core/src/tools/read-file.ts')
| -rw-r--r-- | packages/core/src/tools/read-file.ts | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/packages/core/src/tools/read-file.ts b/packages/core/src/tools/read-file.ts index 4c1d044c..2ab50282 100644 --- a/packages/core/src/tools/read-file.ts +++ b/packages/core/src/tools/read-file.ts @@ -15,6 +15,7 @@ import { ToolLocation, ToolResult, } from './tools.js'; +import { ToolErrorType } from './tool-error.js'; import { PartUnion, Type } from '@google/genai'; import { processSingleFileContent, @@ -78,9 +79,45 @@ 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: result.error, // The detailed error for LLM - returnDisplay: result.returnDisplay || 'Error reading file', // User-friendly error + llmContent, + returnDisplay: result.returnDisplay || 'Error reading file', + error: { + message: result.error, + type: errorType, + }, }; } |
