[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);
});
}
}).exceptionally(throwable -> {
log.error("Failed to perform role change in assignable role place.", throwable);
return null;
});
} else {
assignableRoleService.removeAssignableRoleFromUser(roleById, member)

View File

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

View File

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

View File

@@ -325,6 +325,9 @@ public class InviteLinkFilterServiceBean implements InviteLinkFilterService {
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);
});
CompletableFuture<List<WarnEntry>> future = new CompletableFuture<>();
FutureUtils.toSingleFutureGeneric(allFutures).whenComplete((unused, throwable) -> {
try {
future.complete(self.loadFullWarnEntries(loadedWarnings));
} catch (Exception exception) {
future.completeExceptionally(exception);
}
FutureUtils.toSingleFutureGeneric(allFutures)
.whenComplete((unused, throwable) -> future.complete(self.loadFullWarnEntries(loadedWarnings)))
.exceptionally(throwable -> {
future.completeExceptionally(throwable);
return null;
});
return future;
}

View File

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

View File

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

View File

@@ -155,14 +155,18 @@ public class PurgeServiceBean implements PurgeService {
return aVoid -> {
if (amountToDelete >= 1) {
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) {
deletionFuture.completeExceptionally(throwable);
} else {
deletionFuture.complete(null);
}
}
);
).exceptionally(throwable -> {
deletionFuture.completeExceptionally(throwable);
return null;
});
} else {
log.debug("Completed purging of {} messages.", totalCount);
// 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);
}
});
CompletableFuture<Void> future = new CompletableFuture();
CompletableFuture<Void> future = new CompletableFuture<>();
FutureUtils.toSingleFutureGeneric(notificationFutures)
.whenComplete((unused, throwable) -> future.complete(null));
.whenComplete((unused, throwable) -> future.complete(null))
.exceptionally(throwable -> {
future.completeExceptionally(throwable);
return null;
});
return future;
}

View File

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

View File

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

View File

@@ -36,21 +36,18 @@ public class AUserInAServerParameterHandlerImpl implements AUserInAServerParamet
Parameter cloned = commandService.cloneParameter(param);
cloned.setType(Member.class);
memberParameterHandler.handleAsync(input, iterators, cloned, context, command).whenComplete((o, throwable) -> {
try {
AUserInAServer actualInstance;
if (throwable == null) {
Member member = (Member) o;
actualInstance = userInServerManagementService.loadOrCreateUser(member);
} else {
Long userId = Long.parseLong(((String) input.getValue()).trim());
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);
AUserInAServer actualInstance;
if (throwable == null) {
Member member = (Member) o;
actualInstance = userInServerManagementService.loadOrCreateUser(member);
} else {
Long userId = Long.parseLong(((String) input.getValue()).trim());
actualInstance = userInServerManagementService.loadAUserInAServerOptional(context.getGuild().getIdLong(), userId).orElseThrow(() -> new UserInServerNotFoundException(0L));
}
future.complete(AUserInAServer.builder().userInServerId(actualInstance.getUserInServerId()).build());
}).exceptionally(throwable -> {
future.completeExceptionally(throwable);
return null;
});
return future;
}

View File

@@ -70,6 +70,9 @@ public class CombinedParameterHandlerImpl implements CombinedParametersHandler {
}
}
returningFuture.completeExceptionally(new IncorrectParameterException(command, param.getName()));
}).exceptionally(throwable -> {
returningFuture.completeExceptionally(throwable);
return null;
});
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());
undoActionService.performActionsFuture(commandContext.getUndoActions()).whenComplete((aVoid, undoThrowable) -> {
if(undoThrowable != null) {
log.warn("Undo actions failed.", undoThrowable);
log.error("Undo actions failed.", undoThrowable);
} else {
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.emote(getCachedEmoteFromEmote(reaction.getReactionEmote(), reaction.getGuild()));
future.complete(builder.build());
}).exceptionally(throwable -> {
future.completeExceptionally(throwable);
return null;
});
return future;
}