mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
Improve error reporting of plugins in the Web UI (#557)
Keep the error message and display it in the plugin page when loading the plugin info or the plugin itself fails to load in the Web UI.
This commit is contained in:
1 parent
f702c956a5
commit
9842705eb9
5 files changed
+46
-21
No files matched your search
@@ -38,7 +38,7 @@ async function loadPluginInfos(): Promise<lib.PluginWebpackEnvInfo[]> {
|
||||
pluginList = [];
|
||||
}
|
||||
|
||||
let pluginInfos = [];
|
||||
let pluginInfos: lib.PluginWebpackEnvInfo[] = [];
|
||||
await __webpack_init_sharing__("default");
|
||||
for (let meta of pluginList) {
|
||||
if (meta.web.error) {
|
||||
@@ -59,6 +59,12 @@ async function loadPluginInfos(): Promise<lib.PluginWebpackEnvInfo[]> {
|
||||
pluginInfos.push(pluginInfo);
|
||||
|
||||
} catch (err: any) {
|
||||
pluginInfos.push({
|
||||
name: meta.name,
|
||||
title: meta.name,
|
||||
enabled: false,
|
||||
error: err.message,
|
||||
});
|
||||
logger.error(`Failed to load plugin info for ${meta.name}`);
|
||||
if (err.stack) {
|
||||
logger.error(err.stack);
|
||||
@@ -79,7 +85,8 @@ async function loadPlugins(pluginInfos: lib.PluginWebpackEnvInfo[], control: Con
|
||||
if (pluginInfo.webEntrypoint) {
|
||||
let webModule = (await pluginInfo.container.get(pluginInfo.webEntrypoint))();
|
||||
if (!webModule.WebPlugin) {
|
||||
throw new Error("Plugin webEntrypoint does not export WebPlugin class");
|
||||
pluginInfo.error = "Plugin webEntrypoint does not export WebPlugin class";
|
||||
throw new Error(pluginInfo.error);
|
||||
}
|
||||
WebPluginClass = webModule.WebPlugin;
|
||||
}
|
||||
@@ -89,6 +96,7 @@ async function loadPlugins(pluginInfos: lib.PluginWebpackEnvInfo[], control: Con
|
||||
plugins.set(pluginInfo.name, plugin);
|
||||
|
||||
} catch (err: any) {
|
||||
pluginInfo.error = `Error loading plugin: ${err.message}`;
|
||||
logger.error(`Failed to load plugin ${pluginInfo.name}`);
|
||||
if (err.stack) {
|
||||
logger.error(err.stack);
|
||||
@@ -124,7 +132,7 @@ export default async function bootstrap() {
|
||||
|
||||
let wsUrl = new URL(webRoot, document.location.href);
|
||||
let controlConnector = new ControlConnector(wsUrl.href, 120, undefined);
|
||||
let control = new Control(controlConnector);
|
||||
let control = new Control(controlConnector, new Map(pluginInfos.map(p => [p.name, p])));
|
||||
control.plugins = await loadPlugins(pluginInfos, control);
|
||||
control.inputComponents = inputComponentsFromPlugins(control.plugins);
|
||||
|
||||
|
||||
Reference in new issue
Block a user