[AB-323] improving logging when using whenComplete

This commit is contained in:
Sheldan
2021-08-14 12:15:18 +02:00
parent 3ed1f0c54a
commit 19a4858da1
15 changed files with 88 additions and 52 deletions

View File

@@ -149,6 +149,9 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
self.persistAssignableUser(member, payload, false); self.persistAssignableUser(member, payload, false);
}); });
} }
}).exceptionally(throwable -> {
log.error("Failed to perform role change in assignable role place.", throwable);
return null;
}); });
} else { } else {
assignableRoleService.removeAssignableRoleFromUser(roleById, member) assignableRoleService.removeAssignableRoleFromUser(roleById, member)

View File

@@ -205,16 +205,15 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
if (throwable != null) { if (throwable != null) {
log.warn("Not able to delete old messages of assignable role place {} in server {}.", assignablePlaceId, serverId); log.warn("Not able to delete old messages of assignable role place {} in server {}.", assignablePlaceId, serverId);
} }
try { self.createAssignableRolePlacePost(serverId, assignablePlaceId)
self.createAssignableRolePlacePost(serverId, assignablePlaceId) .thenAccept(unused1 -> postingFuture.complete(null))
.thenAccept(unused1 -> postingFuture.complete(null)) .exceptionally(innerThrowable -> {
.exceptionally(innerThrowable -> { postingFuture.completeExceptionally(innerThrowable);
postingFuture.completeExceptionally(innerThrowable); return null;
return null; });
}); }).exceptionally(throwable -> {
} catch (Exception ex) { postingFuture.completeExceptionally(throwable);
postingFuture.completeExceptionally(ex); return null;
}
}); });
return postingFuture; return postingFuture;
} }
@@ -361,17 +360,16 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
if (throwable != null) { if (throwable != null) {
log.warn("Not able to delete old messages of assignable role place {} in server {}.", assignablePlaceId, serverId); log.warn("Not able to delete old messages of assignable role place {} in server {}.", assignablePlaceId, serverId);
} }
try { self.setupAssignableRolePlaceInChannel(serverId, assignablePlaceId, newChannel)
self.setupAssignableRolePlaceInChannel(serverId, assignablePlaceId, newChannel) .thenAccept(unused1 -> self.updateAssignableRolePlaceChannel(name, newChannel))
.thenAccept(unused1 -> self.updateAssignableRolePlaceChannel(name, newChannel)) .thenAccept(unused1 -> returnFuture.complete(null))
.thenAccept(unused1 -> returnFuture.complete(null)) .exceptionally(innerThrowable -> {
.exceptionally(innerThrowable -> { returnFuture.completeExceptionally(innerThrowable);
returnFuture.completeExceptionally(innerThrowable); return null;
return null; });
}); }).exceptionally(throwable -> {
} catch (Exception ex) { returnFuture.completeExceptionally(throwable);
returnFuture.completeExceptionally(ex); return null;
}
}); });
return returnFuture; return returnFuture;

View File

@@ -166,6 +166,9 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
FutureUtils.toSingleFutureGeneric(memberFutures).whenComplete((unused, throwable) -> { FutureUtils.toSingleFutureGeneric(memberFutures).whenComplete((unused, throwable) -> {
self.updateFoundMembers(memberFutures, serverExp.getServerId(), resultFutures, futures); self.updateFoundMembers(memberFutures, serverExp.getServerId(), resultFutures, futures);
experienceFuture.complete(null); experienceFuture.complete(null);
}).exceptionally(throwable -> {
experienceFuture.completeExceptionally(throwable);
return null;
}); });
}); });
return experienceFuture return experienceFuture

View File

@@ -325,6 +325,9 @@ public class InviteLinkFilterServiceBean implements InviteLinkFilterService {
sendDeletionNotification(deletedInvites, message); sendDeletionNotification(deletedInvites, message);
} }
} }
}).exceptionally(throwable -> {
log.error("Invite matching failed.", throwable);
return null;
}); });
} }

View File

@@ -48,12 +48,11 @@ public class WarnEntryConverter {
allFutures.add(warnedMemberFuture); allFutures.add(warnedMemberFuture);
}); });
CompletableFuture<List<WarnEntry>> future = new CompletableFuture<>(); CompletableFuture<List<WarnEntry>> future = new CompletableFuture<>();
FutureUtils.toSingleFutureGeneric(allFutures).whenComplete((unused, throwable) -> { FutureUtils.toSingleFutureGeneric(allFutures)
try { .whenComplete((unused, throwable) -> future.complete(self.loadFullWarnEntries(loadedWarnings)))
future.complete(self.loadFullWarnEntries(loadedWarnings)); .exceptionally(throwable -> {
} catch (Exception exception) { future.completeExceptionally(throwable);
future.completeExceptionally(exception); return null;
}
}); });
return future; return future;
} }

View File

@@ -90,6 +90,9 @@ public class BanServiceBean implements BanService {
returningFuture.completeExceptionally(throwable1); returningFuture.completeExceptionally(throwable1);
return null; return null;
}); });
}).exceptionally(throwable -> {
returningFuture.completeExceptionally(throwable);
return null;
}); });
return returningFuture; return returningFuture;
} }

View File

@@ -163,6 +163,9 @@ public class MuteServiceBean implements MuteService {
channelService.sendTextToChannel(throwable.getMessage(), feedBackChannel).whenComplete((exceptionMessage, innerThrowable) -> { channelService.sendTextToChannel(throwable.getMessage(), feedBackChannel).whenComplete((exceptionMessage, innerThrowable) -> {
notificationFuture.complete(null); notificationFuture.complete(null);
log.info("Successfully notified user {} in server {} about mute.", memberBeingMuted.getId(), memberBeingMuted.getGuild().getId()); log.info("Successfully notified user {} in server {} about mute.", memberBeingMuted.getId(), memberBeingMuted.getGuild().getId());
}).exceptionally(throwable1 -> {
notificationFuture.completeExceptionally(throwable1);
return null;
}); });
return null; return null;
}); });

View File

@@ -155,14 +155,18 @@ public class PurgeServiceBean implements PurgeService {
return aVoid -> { return aVoid -> {
if (amountToDelete >= 1) { if (amountToDelete >= 1) {
log.debug("Still more than 1 message to delete. Continuing."); log.debug("Still more than 1 message to delete. Continuing.");
purgeMessages(amountToDelete, channel, earliestMessage.getIdLong(), purgedMember, totalCount, currentCount, currentStatusMessageId).whenComplete((avoid, throwable) -> { purgeMessages(amountToDelete, channel, earliestMessage.getIdLong(), purgedMember, totalCount, currentCount, currentStatusMessageId)
.whenComplete((avoid, throwable) -> {
if (throwable != null) { if (throwable != null) {
deletionFuture.completeExceptionally(throwable); deletionFuture.completeExceptionally(throwable);
} else { } else {
deletionFuture.complete(null); deletionFuture.complete(null);
} }
} }
); ).exceptionally(throwable -> {
deletionFuture.completeExceptionally(throwable);
return null;
});
} else { } else {
log.debug("Completed purging of {} messages.", totalCount); log.debug("Completed purging of {} messages.", totalCount);
// Todo Move to message service // Todo Move to message service

View File

@@ -195,9 +195,13 @@ public class WarnServiceBean implements WarnService {
log.warn("Could not find user {} in server {}. Not notifying about decayed warning {}.", userId, serverId, warningId); log.warn("Could not find user {} in server {}. Not notifying about decayed warning {}.", userId, serverId, warningId);
} }
}); });
CompletableFuture<Void> future = new CompletableFuture(); CompletableFuture<Void> future = new CompletableFuture<>();
FutureUtils.toSingleFutureGeneric(notificationFutures) FutureUtils.toSingleFutureGeneric(notificationFutures)
.whenComplete((unused, throwable) -> future.complete(null)); .whenComplete((unused, throwable) -> future.complete(null))
.exceptionally(throwable -> {
future.completeExceptionally(throwable);
return null;
});
return future; return future;
} }

View File

@@ -57,7 +57,10 @@ public class ModMailMessageDeletedListener implements AsyncMessageDeletedListene
} }
CompletableFuture.allOf(dmDeletePromise, channelDeletePromise).whenComplete((unused, throwable) -> CompletableFuture.allOf(dmDeletePromise, channelDeletePromise).whenComplete((unused, throwable) ->
self.removeMessageFromThread(message.getMessageId()) self.removeMessageFromThread(message.getMessageId())
); ).exceptionally(throwable -> {
log.error("Failed to delete message.", throwable);
return null;
});
}); });
}); });
return DefaultListenerResult.PROCESSED; return DefaultListenerResult.PROCESSED;

View File

@@ -233,10 +233,10 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
CompletableFuture<Void> headerFuture = sendModMailHeader(channel, member); CompletableFuture<Void> headerFuture = sendModMailHeader(channel, member);
CompletableFuture<Message> userReplyMessage; CompletableFuture<Message> userReplyMessage;
if(initialMessage != null){ if(initialMessage != null){
log.debug("Sending initial message {} of user {} to modmail thread {}.", initialMessage.getId(), member.getId(), channel.getId()); log.info("Sending initial message {} of user {} to modmail thread {}.", initialMessage.getId(), member.getId(), channel.getId());
userReplyMessage = self.sendUserReply(channel, 0L, initialMessage, member, false); userReplyMessage = self.sendUserReply(channel, 0L, initialMessage, member, false);
} else { } else {
log.debug("No initial message to send."); log.info("No initial message to send.");
userReplyMessage = CompletableFuture.completedFuture(null); userReplyMessage = CompletableFuture.completedFuture(null);
} }
CompletableFuture notificationFuture; CompletableFuture notificationFuture;
@@ -349,6 +349,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
} }
log.info("There were {} shared servers found which have modmail enabled.", availableGuilds.size()); log.info("There were {} shared servers found which have modmail enabled.", availableGuilds.size());
// if more than 1 server is available, show a choice dialog // if more than 1 server is available, show a choice dialog
ArrayList<UndoActionInstance> undoActions = new ArrayList<>();
if(availableGuilds.size() > 1) { if(availableGuilds.size() > 1) {
ModMailServerChooserModel modMailServerChooserModel = ModMailServerChooserModel ModMailServerChooserModel modMailServerChooserModel = ModMailServerChooserModel
.builder() .builder()
@@ -365,7 +366,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
log.debug("Executing action for creationg a modmail thread in server {} for user {}.", chosenServerId, userId); log.debug("Executing action for creationg a modmail thread in server {} for user {}.", chosenServerId, userId);
memberService.getMemberInServerAsync(chosenServerId, userId).thenCompose(member -> { memberService.getMemberInServerAsync(chosenServerId, userId).thenCompose(member -> {
try { try {
return self.createModMailThreadForUser(member, initialMessage, initialMessage.getChannel(), true, new ArrayList<>()); return self.createModMailThreadForUser(member, initialMessage, initialMessage.getChannel(), true, undoActions);
} catch (Exception exception) { } catch (Exception exception) {
log.error("Setting up modmail thread for user {} in server {} failed.", userId, chosenServerId, exception); log.error("Setting up modmail thread for user {} in server {} failed.", userId, chosenServerId, exception);
CompletableFuture<Void> future = new CompletableFuture<>(); CompletableFuture<Void> future = new CompletableFuture<>();
@@ -374,6 +375,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
} }
}).exceptionally(throwable -> { }).exceptionally(throwable -> {
log.error("Failed to load member {} for modmail in server {}.", userId, chosenServerId, throwable); log.error("Failed to load member {} for modmail in server {}.", userId, chosenServerId, throwable);
undoActionService.performActions(undoActions);
return null; return null;
}); });
}) })
@@ -386,7 +388,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
log.info("Only one server available to modmail. Directly opening modmail thread for user {} in server {}.", initialMessage.getAuthor().getId(), chosenServerId); log.info("Only one server available to modmail. Directly opening modmail thread for user {} in server {}.", initialMessage.getAuthor().getId(), chosenServerId);
memberService.getMemberInServerAsync(chosenServerId, initialMessage.getAuthor().getIdLong()).thenCompose(member -> { memberService.getMemberInServerAsync(chosenServerId, initialMessage.getAuthor().getIdLong()).thenCompose(member -> {
try { try {
return self.createModMailThreadForUser(member, initialMessage, initialMessage.getChannel(), true, new ArrayList<>()); return self.createModMailThreadForUser(member, initialMessage, initialMessage.getChannel(), true, undoActions);
} catch (Exception exception) { } catch (Exception exception) {
CompletableFuture<Void> future = new CompletableFuture<>(); CompletableFuture<Void> future = new CompletableFuture<>();
future.completeExceptionally(exception); future.completeExceptionally(exception);
@@ -394,6 +396,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
} }
}).exceptionally(throwable -> { }).exceptionally(throwable -> {
log.error("Failed to setup thread correctly", throwable); log.error("Failed to setup thread correctly", throwable);
undoActionService.performActions(undoActions);
return null; return null;
}); });
} else { } else {
@@ -479,9 +482,10 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
if(subscriberList.isEmpty()) { if(subscriberList.isEmpty()) {
subscriberMemberFutures.add(CompletableFuture.completedFuture(null)); subscriberMemberFutures.add(CompletableFuture.completedFuture(null));
} }
log.debug("Mentioning {} subscribers for modmail thread {}.", subscriberList.size(), modMailThreadId); log.info("Mentioning {} subscribers for modmail thread {}.", subscriberList.size(), modMailThreadId);
} else { } else {
subscriberMemberFutures.add(CompletableFuture.completedFuture(null)); subscriberMemberFutures.add(CompletableFuture.completedFuture(null));
log.info("Initial setup of modmail - not mentioning subscribers.");
} }
CompletableFuture<Message> messageFuture = new CompletableFuture<>(); CompletableFuture<Message> messageFuture = new CompletableFuture<>();
FutureUtils.toSingleFutureGeneric(subscriberMemberFutures).whenComplete((unused, throwable) -> { FutureUtils.toSingleFutureGeneric(subscriberMemberFutures).whenComplete((unused, throwable) -> {
@@ -518,6 +522,9 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
messageFuture.completeExceptionally(throwable1); messageFuture.completeExceptionally(throwable1);
return null; return null;
}); });
}).exceptionally(throwable -> {
messageFuture.completeExceptionally(throwable);
return null;
}); });
return messageFuture; return messageFuture;

View File

@@ -36,21 +36,18 @@ public class AUserInAServerParameterHandlerImpl implements AUserInAServerParamet
Parameter cloned = commandService.cloneParameter(param); Parameter cloned = commandService.cloneParameter(param);
cloned.setType(Member.class); cloned.setType(Member.class);
memberParameterHandler.handleAsync(input, iterators, cloned, context, command).whenComplete((o, throwable) -> { memberParameterHandler.handleAsync(input, iterators, cloned, context, command).whenComplete((o, throwable) -> {
try { AUserInAServer actualInstance;
AUserInAServer actualInstance; if (throwable == null) {
if (throwable == null) { Member member = (Member) o;
Member member = (Member) o; actualInstance = userInServerManagementService.loadOrCreateUser(member);
actualInstance = userInServerManagementService.loadOrCreateUser(member); } else {
} else { Long userId = Long.parseLong(((String) input.getValue()).trim());
Long userId = Long.parseLong(((String) input.getValue()).trim()); actualInstance = userInServerManagementService.loadAUserInAServerOptional(context.getGuild().getIdLong(), userId).orElseThrow(() -> new UserInServerNotFoundException(0L));
actualInstance = userInServerManagementService.loadAUserInAServerOptional(context.getGuild().getIdLong(), userId).orElseThrow(() -> new UserInServerNotFoundException(0L));
}
future.complete(AUserInAServer.builder().userInServerId(actualInstance.getUserInServerId()).build());
} catch (Exception e) {
// we need to do it like this, because when complete only returns the exception it got in case two exceptions happen
// so if the first exception happens in handleAsync, and we also throw one, it will _not_ get reported, because the other exception overshadows it
future.completeExceptionally(e);
} }
future.complete(AUserInAServer.builder().userInServerId(actualInstance.getUserInServerId()).build());
}).exceptionally(throwable -> {
future.completeExceptionally(throwable);
return null;
}); });
return future; return future;
} }

View File

@@ -70,6 +70,9 @@ public class CombinedParameterHandlerImpl implements CombinedParametersHandler {
} }
} }
returningFuture.completeExceptionally(new IncorrectParameterException(command, param.getName())); returningFuture.completeExceptionally(new IncorrectParameterException(command, param.getName()));
}).exceptionally(throwable -> {
returningFuture.completeExceptionally(throwable);
return null;
}); });
return returningFuture; return returningFuture;
} }

View File

@@ -24,10 +24,13 @@ public class UndoActionPostExecution implements PostCommandExecution {
log.info("Performing undo cations for command {} in server {}.", command.getConfiguration().getName(), commandContext.getGuild().getIdLong()); log.info("Performing undo cations for command {} in server {}.", command.getConfiguration().getName(), commandContext.getGuild().getIdLong());
undoActionService.performActionsFuture(commandContext.getUndoActions()).whenComplete((aVoid, undoThrowable) -> { undoActionService.performActionsFuture(commandContext.getUndoActions()).whenComplete((aVoid, undoThrowable) -> {
if(undoThrowable != null) { if(undoThrowable != null) {
log.warn("Undo actions failed.", undoThrowable); log.error("Undo actions failed.", undoThrowable);
} else { } else {
log.info("Successfully executed undo actions."); log.info("Successfully executed undo actions.");
} }
}).exceptionally(throwable -> {
log.error("Undo complete failed.", throwable);
return null;
}); });
} }
} }

View File

@@ -184,6 +184,9 @@ public class CacheEntityServiceBean implements CacheEntityService {
builder.self(reaction.isSelf()); builder.self(reaction.isSelf());
builder.emote(getCachedEmoteFromEmote(reaction.getReactionEmote(), reaction.getGuild())); builder.emote(getCachedEmoteFromEmote(reaction.getReactionEmote(), reaction.getGuild()));
future.complete(builder.build()); future.complete(builder.build());
}).exceptionally(throwable -> {
future.completeExceptionally(throwable);
return null;
}); });
return future; return future;
} }