Skip to content

Commit e88df90

Browse files
committed
modals: Improve error when resolver returns null
1 parent cf40ed7 commit e88df90

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/modals/ModalHandlerInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ internal class ModalHandlerInfo internal constructor(
105105
option.resolver.resolveSuspend(option, event, modalMapping).also { obj ->
106106
// Technically not required, but provides additional info
107107
requireUser(obj != null || option.isOptionalOrNullable) {
108-
"The parameter '${option.declaredName}' from $modalMapping and value ${modalMapping.valueAsString} is required but was resolved to null"
108+
"The parameter '${option.declaredName}' is required but was resolved to null (from a ${modalMapping.type.name} with ID '${modalMapping.customId}' and value ${modalMapping.valueAsString})"
109109
}
110110
}
111111
}

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/modals/utils/ModalMappings.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ internal val ModalInteractionEvent.allValuesAsString: String
1010
internal val ModalMapping.valueAsString: String
1111
get() = when (type) {
1212
STRING_SELECT, CHECKBOX_GROUP -> asStringList.map { "'${it}'" }.toString()
13-
TEXT_INPUT, RADIO_GROUP -> if (asOptionalString == null) "<null>" else "'${asString}'"
13+
TEXT_INPUT -> if (asOptionalString == null) "<empty>" else "'${asString}'"
14+
RADIO_GROUP -> if (asOptionalString == null) "<none>" else "'${asString}'"
1415
CHANNEL_SELECT, ROLE_SELECT, USER_SELECT, MENTIONABLE_SELECT -> asLongList.toString()
1516
FILE_UPLOAD -> asAttachmentList.map { "${it.fileName} (${it.contentType}, ${it.size} B)" }.toString()
1617
CHECKBOX -> "<$asBoolean>"

0 commit comments

Comments
 (0)