Skip to content

Commit d947ee5

Browse files
committed
fix(endpoints): handle exceptions in WebApiViewFunctionProvider
Wrap the endpoint collection logic in a try-catch block to handle potential ClassCastException and other exceptions, ensuring the CompletableFuture completes exceptionally in case of errors
1 parent 9035f46 commit d947ee5

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

exts/ext-endpoints/src/233/main/kotlin/cc/unitmesh/endpoints/bridge/WebApiViewFunctionProvider.kt

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
1111
import com.intellij.openapi.project.Project
1212
import com.intellij.spring.mvc.mapping.UrlMappingElement
1313
import java.util.concurrent.CompletableFuture
14+
import java.util.concurrent.TimeUnit
1415

1516
class WebApiViewFunctionProvider : ToolchainFunctionProvider {
1617
override fun funcNames(): List<String> = listOf(ArchViewCommand.WebApiView.name)
@@ -26,25 +27,30 @@ class WebApiViewFunctionProvider : ToolchainFunctionProvider {
2627
val future = CompletableFuture<String>()
2728
val task = object : Task.Backgroundable(project, "Processing context", false) {
2829
override fun run(indicator: ProgressIndicator) {
29-
val endpointsProviderList = runReadAction { EndpointsProvider.getAvailableProviders(project).toList() }
30-
if (endpointsProviderList.isEmpty()) {
31-
future.complete("Cannot find any endpoints")
32-
return
30+
try {
31+
val endpointsProviderList = runReadAction {
32+
EndpointsProvider.getAvailableProviders(project).toList()
33+
}
34+
if (endpointsProviderList.isEmpty()) {
35+
future.complete("Cannot find any endpoints")
36+
return
37+
}
38+
39+
/// java.lang.ClassCastException: class com.intellij.micronaut.jam.http.MnController cannot be cast to class
40+
// com.intellij.spring.model.SpringBeanPointer (com.intellij.micronaut.jam.http.MnController is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @5d6888bf; com.intellij.spring.model.SpringBeanPointer is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @775c694b)
41+
val map = collectUrls(project, endpointsProviderList)
42+
val result =
43+
"Here is current project web ${map.size} api endpoints: \n```\n" + map.joinToString("\n") { url ->
44+
url.method.joinToString("\n") {
45+
"$it - ${url.urlPath.toStringWithStars()}" +
46+
" (${UrlMappingElement.getContainingFileName(url)})"
47+
}
48+
} + "\n```"
49+
50+
future.complete(result)
51+
} catch (e: Exception) {
52+
future.completeExceptionally(e)
3353
}
34-
35-
val map = collectUrls(project, endpointsProviderList)
36-
val result =
37-
"Here is current project web ${map.size} api endpoints: \n```\n" + map.joinToString("\n") { url ->
38-
url.method.joinToString("\n") {
39-
"$it - ${url.urlPath.toStringWithStars()}" + " (${
40-
UrlMappingElement.getContainingFileName(
41-
url
42-
)
43-
})"
44-
}
45-
} + "\n```"
46-
47-
future.complete(result)
4854
}
4955
}
5056

0 commit comments

Comments
 (0)