fix: log plugin load errors in gateway
This commit is contained in:
@@ -7,6 +7,9 @@ Docs: https://docs.clawd.bot
|
||||
### Changes
|
||||
- Usage: add `/usage cost` summaries and macOS menu cost submenu with daily charting.
|
||||
|
||||
### Fixes
|
||||
- Plugins: surface plugin load/register/config errors in gateway logs with plugin/source context.
|
||||
|
||||
## 2026.1.18-5
|
||||
|
||||
### Changes
|
||||
|
||||
58
src/gateway/server-plugins.test.ts
Normal file
58
src/gateway/server-plugins.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import type { PluginRegistry } from "../plugins/registry.js";
|
||||
import type { PluginDiagnostic } from "../plugins/types.js";
|
||||
import { loadGatewayPlugins } from "./server-plugins.js";
|
||||
|
||||
const loadClawdbotPlugins = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("../plugins/loader.js", () => ({
|
||||
loadClawdbotPlugins,
|
||||
}));
|
||||
|
||||
const createRegistry = (diagnostics: PluginDiagnostic[]): PluginRegistry => ({
|
||||
plugins: [],
|
||||
tools: [],
|
||||
hooks: [],
|
||||
typedHooks: [],
|
||||
channels: [],
|
||||
providers: [],
|
||||
gatewayHandlers: {},
|
||||
httpHandlers: [],
|
||||
cliRegistrars: [],
|
||||
services: [],
|
||||
diagnostics,
|
||||
});
|
||||
|
||||
describe("loadGatewayPlugins", () => {
|
||||
test("logs plugin errors with details", () => {
|
||||
const diagnostics: PluginDiagnostic[] = [
|
||||
{
|
||||
level: "error",
|
||||
pluginId: "telegram",
|
||||
source: "/tmp/telegram/index.ts",
|
||||
message: "failed to load plugin: boom",
|
||||
},
|
||||
];
|
||||
loadClawdbotPlugins.mockReturnValue(createRegistry(diagnostics));
|
||||
|
||||
const log = {
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
debug: vi.fn(),
|
||||
};
|
||||
|
||||
loadGatewayPlugins({
|
||||
cfg: {},
|
||||
workspaceDir: "/tmp",
|
||||
log,
|
||||
coreGatewayHandlers: {},
|
||||
baseMethods: [],
|
||||
});
|
||||
|
||||
expect(log.error).toHaveBeenCalledWith(
|
||||
"[plugins] failed to load plugin: boom (plugin=telegram, source=/tmp/telegram/index.ts)",
|
||||
);
|
||||
expect(log.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -29,10 +29,19 @@ export function loadGatewayPlugins(params: {
|
||||
const gatewayMethods = Array.from(new Set([...params.baseMethods, ...pluginMethods]));
|
||||
if (pluginRegistry.diagnostics.length > 0) {
|
||||
for (const diag of pluginRegistry.diagnostics) {
|
||||
const details = [
|
||||
diag.pluginId ? `plugin=${diag.pluginId}` : null,
|
||||
diag.source ? `source=${diag.source}` : null,
|
||||
]
|
||||
.filter((entry): entry is string => Boolean(entry))
|
||||
.join(", ");
|
||||
const message = details
|
||||
? `[plugins] ${diag.message} (${details})`
|
||||
: `[plugins] ${diag.message}`;
|
||||
if (diag.level === "error") {
|
||||
params.log.warn(`[plugins] ${diag.message}`);
|
||||
params.log.error(message);
|
||||
} else {
|
||||
params.log.info(`[plugins] ${diag.message}`);
|
||||
params.log.info(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,6 +376,9 @@ export function loadClawdbotPlugins(options: PluginLoadOptions = {}): PluginRegi
|
||||
try {
|
||||
mod = jiti(candidate.source) as ClawdbotPluginModule;
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
`[plugins] ${record.id} failed to load from ${record.source}: ${String(err)}`,
|
||||
);
|
||||
record.status = "error";
|
||||
record.error = String(err);
|
||||
registry.plugins.push(record);
|
||||
@@ -460,6 +463,9 @@ export function loadClawdbotPlugins(options: PluginLoadOptions = {}): PluginRegi
|
||||
});
|
||||
|
||||
if (!validatedConfig.ok) {
|
||||
logger.error(
|
||||
`[plugins] ${record.id} invalid config: ${validatedConfig.errors?.join(", ")}`,
|
||||
);
|
||||
record.status = "error";
|
||||
record.error = `invalid config: ${validatedConfig.errors?.join(", ")}`;
|
||||
registry.plugins.push(record);
|
||||
@@ -474,6 +480,7 @@ export function loadClawdbotPlugins(options: PluginLoadOptions = {}): PluginRegi
|
||||
}
|
||||
|
||||
if (typeof register !== "function") {
|
||||
logger.error(`[plugins] ${record.id} missing register/activate export`);
|
||||
record.status = "error";
|
||||
record.error = "plugin export missing register/activate";
|
||||
registry.plugins.push(record);
|
||||
@@ -505,6 +512,9 @@ export function loadClawdbotPlugins(options: PluginLoadOptions = {}): PluginRegi
|
||||
registry.plugins.push(record);
|
||||
seenIds.set(candidate.idHint, candidate.origin);
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
`[plugins] ${record.id} failed during register from ${record.source}: ${String(err)}`,
|
||||
);
|
||||
record.status = "error";
|
||||
record.error = String(err);
|
||||
registry.plugins.push(record);
|
||||
|
||||
Reference in New Issue
Block a user