Skip to content

Commit

Permalink
feat: server won't crash if failed to load the descriptor of a plugin…
Browse files Browse the repository at this point in the history
… now. An error message will be print to the console instead
  • Loading branch information
smartcmd committed Jan 22, 2025
1 parent 2ba578b commit c10874d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Unless otherwise specified, any version comparison below is the comparison of se
- (API) Renamed `FullContainerTypeBuilder` to `Builder`
- World will be skipped if failed to be load.
- Main thread will sleep a short time if gui is enabled when the server exits abnormally. This gives user time to see what goes wrong.
- Server won't crash if failed to load the descriptor of a plugin now. An error message will be print to the console instead.

### Fixed

Expand Down
27 changes: 16 additions & 11 deletions api/src/main/java/org/allaymc/api/i18n/TrKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,11 @@ public interface TrKeys {
*/
String A_PLUGIN_DEPENDENCY_VERSION_MISMATCH = "allay:plugin.dependency.version.mismatch";

/**
* Error while loading the descriptor of plugin %1: %2
*/
String A_PLUGIN_DESCRIPTOR_ERROR = "allay:plugin.descriptor.error";

/**
* Error while disabling plugin %1. Error: %2
*/
Expand Down Expand Up @@ -543,35 +548,35 @@ public interface TrKeys {
String A_PLUGIN_LOADING = "allay:plugin.loading";

/**
* Loaded %1 recipes
*/
String A_RECIPE_LOADED = "allay:recipe.loaded";

/**
* Loading recipes...
* Loaded %1 furnace recipes
*/
String A_RECIPE_LOADING = "allay:recipe.loading";
String A_RECIPE_FURNACE_LOADED = "allay:recipe.furnace.loaded";

/**
* Loading furnace recipes...
*/
String A_RECIPE_FURNACE_LOADING = "allay:recipe.furnace.loading";

/**
* Loaded %1 furnace recipes
* Loaded %1 recipes
*/
String A_RECIPE_FURNACE_LOADED = "allay:recipe.furnace.loaded";
String A_RECIPE_LOADED = "allay:recipe.loaded";

/**
* Loading potion mix recipes...
* Loading recipes...
*/
String A_RECIPE_POTIONMIX_LOADING = "allay:recipe.potionmix.loading";
String A_RECIPE_LOADING = "allay:recipe.loading";

/**
* Loaded %1 potion mix recipes
*/
String A_RECIPE_POTIONMIX_LOADED = "allay:recipe.potionmix.loaded";

/**
* Loading potion mix recipes...
*/
String A_RECIPE_POTIONMIX_LOADING = "allay:recipe.potionmix.loading";

/**
* §eYou are running a development version. The development version may have unexpected bugs, please do not use it in a production environment!
*/
Expand Down
1 change: 1 addition & 0 deletions data/resources/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"allay:plugin.dependency.circular": "Circular dependencies appear in plugin %1: %2 The plugin will skip loading!",
"allay:plugin.dependency.missing": "Plugin %1 is depending on plugin %2, which is not found",
"allay:plugin.dependency.version.mismatch": "Plugin %1 expects dependency %2 version in %3, but got version %4",
"allay:plugin.descriptor.error": "Error while loading the descriptor of plugin %1: %2",
"allay:plugin.disable.error": "Error while disabling plugin %1. Error: %2",
"allay:plugin.disabling": "Disabling plugin %1",
"allay:plugin.duplicate": "Find duplicate plugin %1",
Expand Down
1 change: 1 addition & 0 deletions data/resources/lang/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"allay:plugin.dependency.circular": "插件 %1 存在循环依赖: %2 此插件将跳过加载!",
"allay:plugin.dependency.missing": "插件 %1 缺少依赖 %2",
"allay:plugin.dependency.version.mismatch": "插件 %1 需要依赖 %2 的版本满足 %3, 但实际版本为 %4",
"allay:plugin.descriptor.error": "加载插件 %1 的描述符时发生错误: %2",
"allay:plugin.disable.error": "卸载插件 %1 时发生错误: %2",
"allay:plugin.disabling": "正在关闭插件 %1",
"allay:plugin.duplicate": "找到重复的插件 %1",
Expand Down
1 change: 1 addition & 0 deletions data/resources/unpacked/lang_raw/allay/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"plugin.construct.instance.error": "Error while constructing plugin instance for plugin %1. Error: %2",
"plugin.entrance.missing": "Can't find the entrance of plugin %1",
"plugin.jar.entrance.typeinvalid": "The entrance class of plugin %1 is not a subclass of Plugin",
"plugin.descriptor.error": "Error while loading the descriptor of plugin %1: %2",
"extension.loading": "loading extension %1",
"extension.construct.instance.error": "Error while constructing extension instance for extension %1. Error: %2",
"extension.entrance.missing": "Can't find the entrance of extension %1",
Expand Down
1 change: 1 addition & 0 deletions data/resources/unpacked/lang_raw/allay/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"plugin.construct.instance.error": "创建插件 %1 实例时发生错误 %2",
"plugin.entrance.missing": "无法找到插件 %1 的入口",
"plugin.jar.mainclass.typeinvalid": "插件 %1 的主类未继承Plugin",
"plugin.descriptor.error": "加载插件 %1 的描述符时发生错误: %2",
"extension.loading": "正在加载扩展 %1",
"extension.construct.instance.error": "创建扩展 %1 实例时发生错误 %2",
"extension.entrance.missing": "无法找到扩展 %1 的入口",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ protected void findLoadersAndLoadDescriptors(Set<Path> paths, Map<String, Plugin
var loader = findLoader(path);
if (loader == null) continue;

var descriptor = loader.loadDescriptor();
PluginDescriptor descriptor;
try {
descriptor = loader.loadDescriptor();
} catch (Throwable t) {
log.error(I18n.get().tr(TrKeys.A_PLUGIN_DESCRIPTOR_ERROR, path.getFileName(), t.getMessage() != null ? t.getMessage() : ""), t);
continue;
}

var name = descriptor.getName();
if (descriptors.containsKey(name)) {
log.error(I18n.get().tr(TrKeys.A_PLUGIN_DUPLICATE, name));
Expand Down

0 comments on commit c10874d

Please sign in to comment.