()
| 72 | } |
| 73 | |
| 74 | async execute(): Promise<ToolResult> { |
| 75 | const result = await processSingleFileContent( |
| 76 | this.params.absolute_path, |
| 77 | this.config.getTargetDir(), |
| 78 | this.params.offset, |
| 79 | this.params.limit, |
| 80 | ); |
| 81 | |
| 82 | if (result.error) { |
| 83 | // Map error messages to ToolErrorType |
| 84 | let errorType: ToolErrorType; |
| 85 | let llmContent: string; |
| 86 | |
| 87 | // Check error message patterns to determine error type |
| 88 | if ( |
| 89 | result.error.includes('File not found') || |
| 90 | result.error.includes('does not exist') || |
| 91 | result.error.includes('ENOENT') |
| 92 | ) { |
| 93 | errorType = ToolErrorType.FILE_NOT_FOUND; |
| 94 | llmContent = |
| 95 | 'Could not read file because no file was found at the specified path.'; |
| 96 | } else if ( |
| 97 | result.error.includes('is a directory') || |
| 98 | result.error.includes('EISDIR') |
| 99 | ) { |
| 100 | errorType = ToolErrorType.INVALID_TOOL_PARAMS; |
| 101 | llmContent = |
| 102 | 'Could not read file because the provided path is a directory, not a file.'; |
| 103 | } else if ( |
| 104 | result.error.includes('too large') || |
| 105 | result.error.includes('File size exceeds') |
| 106 | ) { |
| 107 | errorType = ToolErrorType.FILE_TOO_LARGE; |
| 108 | llmContent = `Could not read file. ${result.error}`; |
| 109 | } else { |
| 110 | // Other read errors map to READ_CONTENT_FAILURE |
| 111 | errorType = ToolErrorType.READ_CONTENT_FAILURE; |
| 112 | llmContent = `Could not read file. ${result.error}`; |
| 113 | } |
| 114 | |
| 115 | return { |
| 116 | llmContent, |
| 117 | returnDisplay: result.returnDisplay || 'Error reading file', |
| 118 | error: { |
| 119 | message: result.error, |
| 120 | type: errorType, |
| 121 | }, |
| 122 | }; |
| 123 | } |
| 124 | |
| 125 | let llmContent: PartUnion; |
| 126 | if (result.isTruncated) { |
| 127 | const [start, end] = result.linesShown!; |
| 128 | const total = result.originalLineCount!; |
| 129 | const nextOffset = this.params.offset |
| 130 | ? this.params.offset + end - start + 1 |
| 131 | : end; |
nothing calls this directly
no test coverage detected