From 3fbd9a995d46e98e7ec904def3e7eefc8e5b1f03 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sat, 1 Nov 2025 16:10:24 +0000 Subject: [PATCH] Add better plugin index missing error (#799) * Add better plugin load errors * Remove check for permission * Account for packages using different main file --- packages/lib/src/plugin_loader.ts | 10 ++++++++-- test/lib/plugin_loader.js | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/lib/src/plugin_loader.ts b/packages/lib/src/plugin_loader.ts index 45279946..115aef46 100644 --- a/packages/lib/src/plugin_loader.ts +++ b/packages/lib/src/plugin_loader.ts @@ -4,6 +4,7 @@ * @module lib/plugin_loader */ import path from "path"; +import fs from "fs/promises"; import * as libErrors from "./errors"; import * as libPlugin from "./plugin"; import { logger } from "./logging"; @@ -29,8 +30,13 @@ export async function loadPluginInfos(pluginList: Map) { // Check if plugin path exists, otherwise remove it try { require.resolve(pluginPath); - } catch (err) { - logger.error(`Plugin path ${pluginPath} does not exist, not loading ${pluginName}`); + } catch { + let errMsg = `Plugin path ${pluginPath} does not exist`; + try { + await fs.access(pluginPath, fs.constants.F_OK); + errMsg = `Plugin path ${pluginPath} missing index or main file`; + } catch {} + logger.error(`${errMsg}, not loading ${pluginName}`); pluginList.delete(pluginName); continue; } diff --git a/test/lib/plugin_loader.js b/test/lib/plugin_loader.js index 308e3716..f8e275e7 100644 --- a/test/lib/plugin_loader.js +++ b/test/lib/plugin_loader.js @@ -5,7 +5,6 @@ const path = require("path"); const lib = require("@clusterio/lib"); const { BaseControllerPlugin } = require("@clusterio/controller"); -const { escapeRegExp } = lib; describe("lib/plugin_loader", function() { @@ -34,7 +33,10 @@ describe("lib/plugin_loader", function() { }); it("should ignore missing plugins", async function() { - const result = await lib.loadPluginInfos(new Map([["missing", missingPlugin]]), []); + const result = await lib.loadPluginInfos(new Map([ + ["missing", path.resolve(missingPlugin)], + ["no_index", path.resolve(baseDir)], + ]), []); assert.deepEqual(result, []); }); it("should load test plugin", async function() { @@ -46,7 +48,6 @@ describe("lib/plugin_loader", function() { it("should reject on broken plugin", async function() { let brokenMessage; try { - require(path.resolve(brokenPlugin)); } catch (err) { brokenMessage = err.message;