Skip to content

Commit f9b7567

Browse files
committed
fix(hooks): apply unknown-event advisory to legacy config handlers too
1 parent 607ca0f commit f9b7567

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/hooks/loader.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ describe("loader", () => {
279279
expect(event.messages).toEqual(["typo-hook"]);
280280
});
281281

282+
it("registers legacy handler events with unknown keys anyway (advisory)", async () => {
283+
const handlerPath = await writeHandlerModule("legacy-typo-handler.js");
284+
285+
const cfg = createEnabledHooksConfig([
286+
{ event: "command:nwe", module: path.basename(handlerPath) },
287+
]);
288+
289+
const count = await loadInternalHooks(cfg, tmpDir);
290+
expect(count).toBe(1);
291+
expect(getRegisteredEventKeys()).toContain("command:nwe");
292+
});
293+
282294
it("should load multiple handlers", async () => {
283295
// Create test handler modules
284296
const handler1Path = await writeHandlerModule("handler1.js");

src/hooks/loader.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ export async function loadInternalHooks(
274274
continue;
275275
}
276276

277+
// Same advisory typo check as directory-discovered hooks above.
278+
if (!isKnownInternalHookEventKey(handlerConfig.event)) {
279+
log.warn(
280+
`Legacy hook handler ${safeLogValue(rawModule)} subscribes to event ` +
281+
`${safeLogValue(handlerConfig.event)} not emitted by OpenClaw core — ` +
282+
`likely a typo; unless a plugin emits it, the hook never fires. ` +
283+
`Known events: https://docs.openclaw.ai/automation/hooks`,
284+
);
285+
}
277286
registerInternalHook(handlerConfig.event, handler);
278287
loadedHookRegistrations.push({ event: handlerConfig.event, handler });
279288
log.debug(

0 commit comments

Comments
 (0)