Skip to content

Commit 350121d

Browse files
committed
components: Show failing component handler in exception
1 parent 1f18977 commit 350121d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/components/handler/ComponentHandlerContainer.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import io.github.freya022.botcommands.internal.core.BContextImpl
1313
import io.github.freya022.botcommands.internal.core.requiredFilter
1414
import io.github.freya022.botcommands.internal.core.service.FunctionAnnotationsMap
1515
import io.github.freya022.botcommands.internal.utils.FunctionFilter
16+
import io.github.freya022.botcommands.internal.utils.rethrowAt
1617
import io.github.freya022.botcommands.internal.utils.shortSignature
1718
import io.github.freya022.botcommands.internal.utils.throwArgument
1819
import net.dv8tion.jda.api.events.interaction.component.GenericSelectMenuInteractionEvent
@@ -30,7 +31,12 @@ internal class ComponentHandlerContainer(context: BContextImpl, functionAnnotati
3031
.forEach {
3132
val handlerName = it.function.findAnnotationRecursive<JDAButtonListener>()!!.getEffectiveName(it.function)
3233

33-
val oldDescriptor = buttonMap.put(handlerName, ComponentDescriptor(context, it.function, ButtonEvent::class))
34+
val descriptor = try {
35+
ComponentDescriptor(context, it.function, ButtonEvent::class)
36+
} catch (e: Exception) {
37+
e.rethrowAt("Unable to process button handler", it.function)
38+
}
39+
val oldDescriptor = buttonMap.put(handlerName, descriptor)
3440
if (oldDescriptor != null) {
3541
throwArgument("Tried to override a button handler, old method: ${oldDescriptor.function.shortSignature}, new method: ${it.function.shortSignature}")
3642
}
@@ -42,7 +48,11 @@ internal class ComponentHandlerContainer(context: BContextImpl, functionAnnotati
4248
.forEach {
4349
val handlerName = it.function.findAnnotationRecursive<JDASelectMenuListener>()!!.getEffectiveName(it.function)
4450

45-
val oldDescriptor = selectMap.put(handlerName, ComponentDescriptor(context, it.function, GenericSelectMenuInteractionEvent::class))
51+
val oldDescriptor = try {
52+
selectMap.put(handlerName, ComponentDescriptor(context, it.function, GenericSelectMenuInteractionEvent::class))
53+
} catch (e: Exception) {
54+
e.rethrowAt("Unable to process select menu handler", it.function)
55+
}
4656
if (oldDescriptor != null) {
4757
throwArgument("Tried to override a select menu handler, old method: ${oldDescriptor.function.shortSignature}, new method: ${it.function.shortSignature}")
4858
}
@@ -51,4 +61,4 @@ internal class ComponentHandlerContainer(context: BContextImpl, functionAnnotati
5161

5262
fun getButtonDescriptor(handlerName: String) = buttonMap[handlerName]
5363
fun getSelectMenuDescriptor(handlerName: String) = selectMap[handlerName]
54-
}
64+
}

0 commit comments

Comments
 (0)