Skip to content

Commit

Permalink
fix(provider): handle findModuleForFile exceptions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phodal committed Mar 7, 2024
1 parent 5695966 commit a0df305
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -44,7 +44,11 @@ class JavaVersionProvider : ChatContextProvider {
return projectSdk.sdkType is JavaSdkType
}

val module: Module = ModuleUtilCore.findModuleForFile(sourceFile) ?: return false
val module: Module = try {
ModuleUtilCore.findModuleForFile(sourceFile)
} catch (e: Throwable) {
return false
} ?: return false

val sdk = ModuleRootManager.getInstance(module).sdk

Expand Down

0 comments on commit a0df305

Please sign in to comment.