Improve error messages when PluginRemapper fails to initialize (#12598)
This commit is contained in:
@ -75,7 +75,11 @@ public final class PluginRemapper {
|
|||||||
return null;
|
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() {
|
public void shutdown() {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import io.papermc.paper.util.MappingEnvironment;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UncheckedIOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -52,32 +53,35 @@ class RemappedPluginIndex {
|
|||||||
try {
|
try {
|
||||||
Files.createDirectories(this.dir);
|
Files.createDirectories(this.dir);
|
||||||
} catch (final IOException ex) {
|
} catch (final IOException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new UncheckedIOException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.indexFile = dir.resolve(INDEX_FILE_NAME);
|
this.indexFile = dir.resolve(INDEX_FILE_NAME);
|
||||||
if (Files.isRegularFile(this.indexFile)) {
|
if (Files.isRegularFile(this.indexFile)) {
|
||||||
try {
|
this.state = this.readIndex();
|
||||||
this.state = this.readIndex();
|
|
||||||
} catch (final IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.state = new State();
|
this.state = new State();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private State readIndex() throws IOException {
|
private State readIndex() {
|
||||||
final State state;
|
final State state;
|
||||||
try (final BufferedReader reader = Files.newBufferedReader(this.indexFile)) {
|
try (final BufferedReader reader = Files.newBufferedReader(this.indexFile)) {
|
||||||
state = GSON.fromJson(reader, State.class);
|
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 mappings have changed, delete all cached files and create a new index
|
||||||
if (!state.mappingsHash.equals(MappingEnvironment.mappingsHash())) {
|
if (!state.mappingsHash.equals(MappingEnvironment.mappingsHash())) {
|
||||||
for (final String fileName : state.hashes.values()) {
|
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();
|
return new State();
|
||||||
}
|
}
|
||||||
@ -111,10 +115,11 @@ class RemappedPluginIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
|
final Path filePath = this.dir.resolve(fileName);
|
||||||
try {
|
try {
|
||||||
Files.deleteIfExists(this.dir.resolve(fileName));
|
Files.deleteIfExists(filePath);
|
||||||
} catch (final IOException ex) {
|
} catch (final IOException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new UncheckedIOException("Failed to delete no longer needed file '" + filePath + "'", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user