Skip to content

Commit a0df305

Browse files
committed
fix(provider): handle findModuleForFile exceptions
Handle exceptions that might occur during the execution of `ModuleUtilCore.findModuleForFile` method, and return false in case of an exception. The `findModuleForFile` method can throw exceptions, so we need to handle them properly. If an exception occurs, we catch it and return false immediately. This prevents the application from crashing when encountering such exceptions.
1 parent 5695966 commit a0df305

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

java/src/main/kotlin/cc/unitmesh/idea/provider/JavaVersionProvider.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ class JavaVersionProvider : ChatContextProvider {
4444
return projectSdk.sdkType is JavaSdkType
4545
}
4646

47-
val module: Module = ModuleUtilCore.findModuleForFile(sourceFile) ?: return false
47+
val module: Module = try {
48+
ModuleUtilCore.findModuleForFile(sourceFile)
49+
} catch (e: Throwable) {
50+
return false
51+
} ?: return false
4852

4953
val sdk = ModuleRootManager.getInstance(module).sdk
5054

0 commit comments

Comments
 (0)