From 47650100837178e2852bdb50d8c9c6f0cc0bb2e0 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Wed, 28 May 2025 12:33:25 -0700 Subject: [PATCH] Improve error messages when PluginRemapper fails to initialize (#12598) --- .../paper/pluginremap/PluginRemapper.java | 6 ++++- .../pluginremap/RemappedPluginIndex.java | 25 +++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/paper-server/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java b/paper-server/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java index 28857d0c9..fbad4a224 100644 --- a/paper-server/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java +++ b/paper-server/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java @@ -75,7 +75,11 @@ public final class PluginRemapper { return null; } - return new PluginRemapper(pluginsDir); + try { + return new PluginRemapper(pluginsDir); + } catch (final Exception e) { + throw new RuntimeException("Failed to create PluginRemapper, try deleting the '" + pluginsDir.resolve(PAPER_REMAPPED) + "' directory", e); + } } public void shutdown() { diff --git a/paper-server/src/main/java/io/papermc/paper/pluginremap/RemappedPluginIndex.java b/paper-server/src/main/java/io/papermc/paper/pluginremap/RemappedPluginIndex.java index 86fc60452..1a2e8902c 100644 --- a/paper-server/src/main/java/io/papermc/paper/pluginremap/RemappedPluginIndex.java +++ b/paper-server/src/main/java/io/papermc/paper/pluginremap/RemappedPluginIndex.java @@ -8,6 +8,7 @@ import io.papermc.paper.util.MappingEnvironment; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -52,32 +53,35 @@ class RemappedPluginIndex { try { Files.createDirectories(this.dir); } catch (final IOException ex) { - throw new RuntimeException(ex); + throw new UncheckedIOException(ex); } } this.indexFile = dir.resolve(INDEX_FILE_NAME); if (Files.isRegularFile(this.indexFile)) { - try { - this.state = this.readIndex(); - } catch (final IOException e) { - throw new RuntimeException(e); - } + this.state = this.readIndex(); } else { this.state = new State(); } } - private State readIndex() throws IOException { + private State readIndex() { final State state; try (final BufferedReader reader = Files.newBufferedReader(this.indexFile)) { state = GSON.fromJson(reader, State.class); + } catch (final Exception ex) { + throw new RuntimeException("Failed to read index file '" + this.indexFile + "'", ex); } // If mappings have changed, delete all cached files and create a new index if (!state.mappingsHash.equals(MappingEnvironment.mappingsHash())) { for (final String fileName : state.hashes.values()) { - Files.deleteIfExists(this.dir.resolve(fileName)); + final Path path = this.dir.resolve(fileName); + try { + Files.deleteIfExists(path); + } catch (final IOException ex) { + throw new UncheckedIOException("Failed to delete no longer needed file '" + path + "'", ex); + } } return new State(); } @@ -111,10 +115,11 @@ class RemappedPluginIndex { } iterator.remove(); + final Path filePath = this.dir.resolve(fileName); try { - Files.deleteIfExists(this.dir.resolve(fileName)); + Files.deleteIfExists(filePath); } catch (final IOException ex) { - throw new RuntimeException(ex); + throw new UncheckedIOException("Failed to delete no longer needed file '" + filePath + "'", ex); } }