mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
Add better plugin index missing error (#799)
* Add better plugin load errors * Remove check for permission * Account for packages using different main file
This commit is contained in:
1 parent
af299bc08d
commit
3fbd9a995d
2 files changed
+12
-5
No files matched your search
@@ -4,6 +4,7 @@
|
|||||||
* @module lib/plugin_loader
|
* @module lib/plugin_loader
|
||||||
*/
|
*/
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import fs from "fs/promises";
|
||||||
import * as libErrors from "./errors";
|
import * as libErrors from "./errors";
|
||||||
import * as libPlugin from "./plugin";
|
import * as libPlugin from "./plugin";
|
||||||
import { logger } from "./logging";
|
import { logger } from "./logging";
|
||||||
@@ -29,8 +30,13 @@ export async function loadPluginInfos(pluginList: Map<string, string>) {
|
|||||||
// Check if plugin path exists, otherwise remove it
|
// Check if plugin path exists, otherwise remove it
|
||||||
try {
|
try {
|
||||||
require.resolve(pluginPath);
|
require.resolve(pluginPath);
|
||||||
} catch (err) {
|
} catch {
|
||||||
logger.error(`Plugin path ${pluginPath} does not exist, not loading ${pluginName}`);
|
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);
|
pluginList.delete(pluginName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ const path = require("path");
|
|||||||
|
|
||||||
const lib = require("@clusterio/lib");
|
const lib = require("@clusterio/lib");
|
||||||
const { BaseControllerPlugin } = require("@clusterio/controller");
|
const { BaseControllerPlugin } = require("@clusterio/controller");
|
||||||
const { escapeRegExp } = lib;
|
|
||||||
|
|
||||||
|
|
||||||
describe("lib/plugin_loader", function() {
|
describe("lib/plugin_loader", function() {
|
||||||
@@ -34,7 +33,10 @@ describe("lib/plugin_loader", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should ignore missing plugins", async 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, []);
|
assert.deepEqual(result, []);
|
||||||
});
|
});
|
||||||
it("should load test plugin", async function() {
|
it("should load test plugin", async function() {
|
||||||
@@ -46,7 +48,6 @@ describe("lib/plugin_loader", function() {
|
|||||||
it("should reject on broken plugin", async function() {
|
it("should reject on broken plugin", async function() {
|
||||||
let brokenMessage;
|
let brokenMessage;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
require(path.resolve(brokenPlugin));
|
require(path.resolve(brokenPlugin));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
brokenMessage = err.message;
|
brokenMessage = err.message;
|
||||||
|
|||||||
Reference in new issue
Block a user