Skip to content

Commit 41357c5

Browse files
committed
fix(ripgrep): handle binary lookup exceptions gracefully
Wrap ripgrep binary lookup in a try-catch to prevent crashes when binary is not found. Also improve error message when binary is missing.
1 parent d15f221 commit 41357c5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

core/src/main/kotlin/cc/unitmesh/devti/agenttool/search/RipgrepSearcher.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ object RipgrepSearcher {
3030
): CompletableFuture<String?> {
3131
return CompletableFuture.supplyAsync<String> {
3232
try {
33-
val rgPath = findRipgrepBinary() ?: throw IOException("Ripgrep binary not found")
33+
val rgPath = findRipgrepBinary()
34+
if (rgPath == null) {
35+
return@supplyAsync "Ripgrep binary not found, try install it first: https://github.com/BurntSushi/ripgrep?tab=readme-ov-file#installation
36+
}
37+
3438
val results = executeRipgrep(
3539
project,
3640
rgPath,
@@ -59,7 +63,6 @@ object RipgrepSearcher {
5963
}
6064
}
6165
62-
6366
val pb = ProcessBuilder("which", binName)
6467
val process = pb.start()
6568
try {

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/RipgrepSearchInsCommand.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class RipgrepSearchInsCommand(
1212
override val commandName: BuiltinCommand = BuiltinCommand.RIPGREP_SEARCH
1313

1414
override fun isApplicable(): Boolean {
15-
return RipgrepSearcher.findRipgrepBinary() != null
15+
return try {
16+
RipgrepSearcher.findRipgrepBinary() != null
17+
} catch (e: Exception) {
18+
false
19+
}
1620
}
1721

1822
override suspend fun execute(): String? {

0 commit comments

Comments
 (0)