Skip to content

Commit 4d2673d

Browse files
committed
log(application-command): handle null cases
During the event `onStringSelectSelection` which would be called when someone would select one role in the application form, there would be a possibility for: - The `member` to be null (most likely from interacting in a non-guild environment, which is rare and almost impossible). - `event.getSelectedOptions()` to be an empty list, effectively meaning that a form was somehow made with no options and a user (or should we say member in our case) managed to interact with it. In any case, properly log errors in the logger in case either of these happen to be null or otherwise have unexpected values. Suggested-by: Zabuzard <zabuza.dev@gmail.com> Signed-off-by: Chris Sdogkos <work@chris-sdogkos.com>
1 parent c4aeb1a commit 4d2673d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

application/src/main/java/org/togetherjava/tjbot/features/roleapplication/CreateRoleApplicationCommand.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import net.dv8tion.jda.api.interactions.components.text.TextInput;
2121
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
2222
import net.dv8tion.jda.api.interactions.modals.Modal;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
2325

2426
import org.togetherjava.tjbot.config.Config;
2527
import org.togetherjava.tjbot.config.RoleApplicationSystemConfig;
@@ -53,6 +55,9 @@ public class CreateRoleApplicationCommand extends SlashCommandAdapter {
5355
private final RoleApplicationHandler handler;
5456
private final RoleApplicationSystemConfig config;
5557

58+
private static final Logger logger =
59+
LoggerFactory.getLogger(CreateRoleApplicationCommand.class);
60+
5661
/**
5762
* Constructs a new {@link CreateRoleApplicationCommand} with the specified configuration.
5863
* <p>
@@ -119,7 +124,13 @@ public void onStringSelectSelection(StringSelectInteractionEvent event, List<Str
119124
SelectOption selectOption = event.getSelectedOptions().getFirst();
120125
Member member = event.getMember();
121126

122-
if (selectOption == null || member == null) {
127+
if (member == null) {
128+
logger.error("Member was null during onStringSelectSelection()");
129+
return;
130+
}
131+
132+
if (selectOption == null) {
133+
logger.error("selectOption was null during onStringSelectSelection()");
123134
return;
124135
}
125136

0 commit comments

Comments
 (0)