Skip to content

Commit 30e2ad3

Browse files
author
Eric Wheeler
committed
fix: handle unsupported language errors gracefully in read_file tool
Instead of failing with an error when encountering an unsupported language, now logs a warning and continues with file reading. This provides a better user experience by still showing the file contents even if syntax highlighting is not available. Fixes: #3269 Signed-off-by: Eric Wheeler <[email protected]>
1 parent e19bf81 commit 30e2ad3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/core/tools/readFileTool.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,21 @@ export async function readFileTool(
164164

165165
const res = await Promise.all([
166166
maxReadFileLine > 0 ? readLines(absolutePath, maxReadFileLine - 1, 0) : "",
167-
parseSourceCodeDefinitionsForFile(absolutePath, cline.rooIgnoreController),
167+
(async () => {
168+
try {
169+
return await parseSourceCodeDefinitionsForFile(absolutePath, cline.rooIgnoreController)
170+
} catch (error) {
171+
if (error instanceof Error && error.message.startsWith("Unsupported language:")) {
172+
console.warn(`[read_file] Warning: ${error.message}`)
173+
return undefined
174+
} else {
175+
console.error(
176+
`[read_file] Unhandled error: ${error instanceof Error ? error.message : String(error)}`,
177+
)
178+
return undefined
179+
}
180+
}
181+
})(),
168182
])
169183

170184
content = res[0].length > 0 ? addLineNumbers(res[0]) : ""

0 commit comments

Comments
 (0)