Merge pull request #307 from solonovamax/fix/commands-completing-before-execution
Fix cloud swallowing exceptions in `suspend` methods.
This commit is contained in:
parent
ad80933a20
commit
8711d19703
3 changed files with 55 additions and 37 deletions
|
|
@ -89,6 +89,8 @@ public final class AsynchronousCommandExecutionCoordinator<C> extends CommandExe
|
|||
resultFuture.completeExceptionally(new CommandExecutionException(throwable, commandContext));
|
||||
}
|
||||
}
|
||||
// Only complete when the execution is actually finished. See #306 for more info.
|
||||
resultFuture.complete(new CommandResult<>(commandContext));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -97,30 +99,25 @@ public final class AsynchronousCommandExecutionCoordinator<C> extends CommandExe
|
|||
final @NonNull Pair<@Nullable Command<C>, @Nullable Exception> pair =
|
||||
this.getCommandTree().parse(commandContext, input);
|
||||
if (pair.getSecond() != null) {
|
||||
final CompletableFuture<CommandResult<C>> future = new CompletableFuture<>();
|
||||
future.completeExceptionally(pair.getSecond());
|
||||
return future;
|
||||
resultFuture.completeExceptionally(pair.getSecond());
|
||||
} else {
|
||||
this.executor.execute(() -> commandConsumer.accept(pair.getFirst()));
|
||||
}
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
commandConsumer.accept(pair.getFirst());
|
||||
return new CommandResult<>(commandContext);
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
this.executor.execute(() -> {
|
||||
try {
|
||||
final @NonNull Pair<@Nullable Command<C>, @Nullable Exception> pair =
|
||||
this.getCommandTree().parse(commandContext, input);
|
||||
if (pair.getSecond() != null) {
|
||||
resultFuture.completeExceptionally(pair.getSecond());
|
||||
} else {
|
||||
commandConsumer.accept(pair.getFirst());
|
||||
resultFuture.complete(new CommandResult<>(commandContext));
|
||||
} else {
|
||||
this.executor.execute(() -> {
|
||||
try {
|
||||
final @NonNull Pair<@Nullable Command<C>, @Nullable Exception> pair =
|
||||
this.getCommandTree().parse(commandContext, input);
|
||||
if (pair.getSecond() != null) {
|
||||
resultFuture.completeExceptionally(pair.getSecond());
|
||||
} else {
|
||||
commandConsumer.accept(pair.getFirst());
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
resultFuture.completeExceptionally(e);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
resultFuture.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return resultFuture;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue