Skip to content

Commit c180cc8

Browse files
committed
fix(core, terminal): handle JDK resolution exceptions
- Add exception handling when resolving JDK version to prevent crashes - Notify user if JAVA_HOME cannot be set due to an error - Improve error tolerance in terminal runner initialization
1 parent 38abbf7 commit c180cc8

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/run/ProcessExecutor.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,12 @@ class ProcessExecutor(val project: Project) {
136136
commandLine.withEnvironment("TERM", "dumb")
137137
commandLine.withEnvironment("BASH_SILENCE_DEPRECATION_WARNING", "1")
138138
commandLine.withEnvironment("GIT_PAGER", "cat")
139-
getJdkVersion(project)?.let { javaHomePath ->
140-
commandLine.withEnvironment("JAVA_HOME", javaHomePath)
139+
try {
140+
getJdkVersion(project)?.let { javaHomePath ->
141+
commandLine.withEnvironment("JAVA_HOME", javaHomePath)
142+
}
143+
} catch (e: Exception) {
144+
AutoDevNotifications.notify(project, "Failed to get JAVA_HOME: ${e.message}")
141145
}
142146

143147
val commands: List<String> = listOf("bash", "--noprofile", "--norc", "-c", formatCommand(shellScript))
@@ -208,7 +212,12 @@ class ProcessExecutor(val project: Project) {
208212
return javaHome
209213
}
210214

211-
val javaHomeSdk: Sdk? = ExternalSystemJdkUtil.resolveJdkName(null, "#JAVA_HOME")
215+
val javaHomeSdk: Sdk? = try {
216+
ExternalSystemJdkUtil.resolveJdkName(null, "#JAVA_HOME")
217+
} catch (e: Exception) {
218+
null
219+
}
220+
212221
if (javaHomeSdk != null) {
213222
return javaHomeSdk.homePath
214223
}

exts/ext-terminal/src/241/main/kotlin/cc/unitmesh/terminal/service/TerminalRunnerService.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ class TerminalRunnerService(private val project: Project) {
2020
}
2121

2222
fun initializeTerminalRunner(): AbstractTerminalRunner<PtyProcess> {
23-
val runner = LocalTerminalDirectRunner.createTerminalRunner(project)
24-
25-
return runner
23+
return LocalTerminalDirectRunner.createTerminalRunner(project)
2624
}
2725

2826
private fun createStartupOptions(): ShellStartupOptions? {
29-
return ProcessExecutor.getJdkVersion(project)?.let { javaHomePath ->
27+
val jdkVersion = try {
28+
ProcessExecutor.getJdkVersion(project)
29+
} catch (e: Exception) {
30+
null
31+
}
32+
33+
return jdkVersion?.let { javaHomePath ->
3034
val environmentVariables = mapOf("JAVA_HOME" to javaHomePath)
3135
val startupOptions = ShellStartupOptions.Builder()
3236
.envVariables(environmentVariables)

0 commit comments

Comments
 (0)