Skip to content

Commit

Permalink
Actually pass RuntimeExceptions out of paperCommandSendingPool
Browse files Browse the repository at this point in the history
Use IllegalStateException instead of generic RuntimeException to wrap InterruptedException
  • Loading branch information
willkroboth committed Oct 24, 2023
1 parent 77e8def commit 8ce0a6e
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import dev.jorel.commandapi.nms.NMS;
import io.papermc.paper.event.server.ServerResourcesReloadedEvent;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.function.Supplier;

Expand Down Expand Up @@ -150,12 +150,10 @@ public <T> T modifyCommandTreesAndAvoidPaperCME(Supplier<T> modifyTask) {
// Otherwise, submit the modify task to the pool.
// The pool only runs one task at a time (see https://github.com/JorelAli/CommandAPI/pull/501#issuecomment-1773959895),
// so this ensures we don't modify the commands while a command-building process is reading them
CompletableFuture<T> result = new CompletableFuture<>();

paperCommandSendingPool.execute(() -> result.complete(modifyTask.get()));
Future<T> futureResult = paperCommandSendingPool.submit(modifyTask::get);

try {
return result.get();
return futureResult.get();
} catch (ExecutionException e) {
Throwable cause = e.getCause();

Expand All @@ -172,7 +170,7 @@ public <T> T modifyCommandTreesAndAvoidPaperCME(Supplier<T> modifyTask) {
// going to be handled anywhere else, so we just have to wrap it in a RuntimeException and get out of here.
// The `modifyTask` probably did not complete correctly, so we don't have a reasonable result to return.
Thread.currentThread().interrupt();
throw new RuntimeException("The commands could not be updated :(. The thread was interrupted.", e);
throw new IllegalStateException("The commands could not be updated :(. The thread was interrupted.", e);
}
}
}

0 comments on commit 8ce0a6e

Please sign in to comment.