[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

@@ -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;
}