Skip to content

Commit

Permalink
Catch all throwables when loading each extension (#4320)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konicai authored Dec 4, 2023
1 parent 308f293 commit 998caee
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class GeyserExtensionLoader extends ExtensionLoader {
private final Map<Extension, GeyserExtensionContainer> extensionContainers = new HashMap<>();
private final Path extensionsDirectory = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("extensions");

public GeyserExtensionContainer loadExtension(Path path, GeyserExtensionDescription description) throws InvalidExtensionException {
public GeyserExtensionContainer loadExtension(Path path, GeyserExtensionDescription description) throws Throwable {
if (path == null) {
throw new InvalidExtensionException("Path is null");
}
Expand Down Expand Up @@ -92,8 +92,14 @@ public GeyserExtensionContainer loadExtension(Path path, GeyserExtensionDescript

this.classLoaders.put(description.id(), loader);

final Extension extension = loader.load();
return this.setup(extension, description, dataFolder, new GeyserExtensionEventBus(GeyserImpl.getInstance().eventBus(), extension));
try {
final Extension extension = loader.load();
return this.setup(extension, description, dataFolder, new GeyserExtensionEventBus(GeyserImpl.getInstance().eventBus(), extension));
} catch (Throwable e) {
// if the extension failed to load, remove its classloader and close it.
this.classLoaders.remove(description.id()).close();
throw e;
}
}

private GeyserExtensionContainer setup(Extension extension, GeyserExtensionDescription description, Path dataFolder, ExtensionEventBus eventBus) {
Expand Down Expand Up @@ -182,9 +188,10 @@ protected void loadAllExtensions(@NonNull ExtensionManager extensionManager) {
return;
}

GeyserExtensionContainer container = this.loadExtension(path, description);
extensions.put(id, path);
loadedExtensions.put(id, this.loadExtension(path, description));
} catch (Exception e) {
loadedExtensions.put(id, container);
} catch (Throwable e) {
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_with_name", path.getFileName(), path.toAbsolutePath()), e);
}
});
Expand Down

0 comments on commit 998caee

Please sign in to comment.