Skip to content

Commit

Permalink
fix(executor): handle exceptions in ShireDefaultLlmExecutor #60
Browse files Browse the repository at this point in the history
Previously, the ShireDefaultLlmExecutor did not handle exceptions which could lead to unhandled errors during the execution. This commit wraps the LlmProvider streaming process with a try-catch block to print error messages and detach the process in case of exceptions. This ensures a more robust and user-friendly error handling within the executor.
  • Loading branch information
phodal committed Aug 26, 2024
1 parent f2b0d63 commit da44e85
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ class ShireDefaultLlmExecutor(
ShireCoroutineScope.scope(context.myProject).launch {
val llmResult = StringBuilder()
runBlocking {
LlmProvider.provider(context.myProject)?.stream(context.prompt, "", false)?.collect {
llmResult.append(it)
try {
LlmProvider.provider(context.myProject)?.stream(context.prompt, "", false)?.collect {
llmResult.append(it)

context.console.print(it, ConsoleViewContentType.NORMAL_OUTPUT)
} ?: context.console.print(
ShireBundle.message("shire.llm.notfound"),
ConsoleViewContentType.ERROR_OUTPUT
)
context.console.print(it, ConsoleViewContentType.NORMAL_OUTPUT)
} ?: context.console.print(
ShireBundle.message("shire.llm.notfound"),
ConsoleViewContentType.ERROR_OUTPUT
)
} catch (e: Exception) {
context.console.print(e.message ?: "Error", ConsoleViewContentType.ERROR_OUTPUT)
context.processHandler.detachProcess()
}
}

context.console.print(ShireBundle.message("shire.llm.done"), ConsoleViewContentType.SYSTEM_OUTPUT)
Expand Down

0 comments on commit da44e85

Please sign in to comment.