From 1868973eeecae02e5c2525fb126a7434eda7df01 Mon Sep 17 00:00:00 2001 From: Frederik van der Els Date: Tue, 20 Feb 2024 00:48:00 +0100 Subject: [PATCH] Fail CompletableFuture on exception --- .../clientcommands/features/MappingsHelper.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/features/MappingsHelper.java b/src/main/java/net/earthcomputer/clientcommands/features/MappingsHelper.java index e4b86ba5b..1c2eea2c2 100644 --- a/src/main/java/net/earthcomputer/clientcommands/features/MappingsHelper.java +++ b/src/main/java/net/earthcomputer/clientcommands/features/MappingsHelper.java @@ -22,6 +22,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringReader; +import java.io.UncheckedIOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -94,19 +95,21 @@ public class MappingsHelper { }) .thenApply(HttpResponse::body) .thenApply(body -> { - MemoryMappingTree tree = new MemoryMappingTree(); try (StringReader reader = new StringReader(body)) { + MemoryMappingTree tree = new MemoryMappingTree(); MappingReader.read(reader, MappingFormat.PROGUARD_FILE, tree); + return tree; } catch (IOException ex) { LOGGER.error("Could not read ProGuard mappings file", ex); ListenCommand.isEnabled = false; + throw new UncheckedIOException(ex); + } finally { + try (BufferedWriter writer = Files.newBufferedWriter(MAPPINGS_DIR.resolve(version + ".txt"), StandardOpenOption.CREATE)) { + writer.write(body); + } catch (IOException ex) { + LOGGER.error("Could not write ProGuard mappings file", ex); + } } - try (BufferedWriter writer = Files.newBufferedWriter(MAPPINGS_DIR.resolve(version + ".txt"), StandardOpenOption.CREATE)) { - writer.write(body); - } catch (IOException ex) { - LOGGER.error("Could not write ProGuard mappings file", ex); - } - return tree; }); } });