Skip to content

Commit

Permalink
Prevent npe on error code generation if error has no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Alf-Melmac committed Apr 10, 2023
1 parent 9abffef commit ddbea28
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onSlashCommandInteraction(@NonNull SlashCommandInteractionEvent even
}

private void unknownException(@NonNull GenericCommandInteractionEvent event, @NonNull Class<?> commandClass, ReflectiveOperationException e) {
final String errorCode = UUID.nameUUIDFromBytes(e.getMessage().getBytes()).toString();
final String errorCode = getErrorCode(e);
log.error("Failed to execute command interaction {} with options {} - {}", commandClass.getName(), event.getOptions(), errorCode, e);
failedInteraction(event, "Sorry. Error Code: `" + errorCode + "`");
}
Expand Down Expand Up @@ -106,7 +106,7 @@ public void onStringSelectInteraction(@NonNull StringSelectInteractionEvent even
}

private void unknownException(@NonNull StringSelectInteractionEvent event, @NonNull Class<?> commandClass, ReflectiveOperationException e) {
final String errorCode = UUID.nameUUIDFromBytes(e.getMessage().getBytes()).toString();
final String errorCode = getErrorCode(e);
log.error("Failed to process string selection menu selection {} with id {} - {}", commandClass.getName(), event.getComponentId(), errorCode, e);
replyAndRemoveComponents(event, "Sorry. Error Code: `" + errorCode + "`");
}
Expand All @@ -132,4 +132,9 @@ public void onUserContextInteraction(@NonNull UserContextInteractionEvent event)
unknownException(event, commandClass, e);
}
}

private String getErrorCode(ReflectiveOperationException e) {
final String message = e.getMessage();
return message != null ? UUID.nameUUIDFromBytes(message.getBytes()).toString() : UUID.randomUUID().toString();
}
}

0 comments on commit ddbea28

Please sign in to comment.