diegosouzapw/OmniRoute · error
Hook " " is already registered
Error message
Hook "${config.name}" is already registered What it means
registerHook found an entry with the same config.name already present in the registry state. Duplicate registration is rejected outright (not merged or replaced) so hook execution order and middleware wiring stay deterministic.
Solutions
- Unregister the existing hook before re-registering the name
- Choose a distinct hook name
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/lib/middleware/registry.ts:205 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/ac85491889077716.
Report an issue: GitHub.
Appendix: source
Thrown at src/lib/middleware/registry.ts:205
info: (tag: string, msg: string) => logger.info?.(tag, msg) ?? console.log(`[${tag}] ${msg}`),
warn: (tag: string, msg: string) =>
logger.warn?.(tag, msg) ?? console.warn(`[${tag}] ${msg}`),
error: (tag: string, msg: string) =>
logger.error?.(tag, msg) ?? console.error(`[${tag}] ${msg}`),
},
};
}
// ── Public API ────────────────────────────────────────────────────────────
/**
* Register a pre-request hook.
*/
export function registerHook(config: HookConfig, middleware?: HookMiddleware): void {
const state = getRegistryState();
if (state.hooks.has(config.name)) {
throw new Error(`Hook "${config.name}" is already registered`);
}
state.hooks.set(config.name, { ...config });
if (middleware) {
state.middlewares.set(config.name, middleware);
} else {
// Compile from code
const compiled = compileHookCode(config.code, config.name);
state.middlewares.set(config.name, compiled);
}
}
/**
* Unregister a hook by name.
*/
export function unregisterHook(name: string): boolean {
const state = getRegistryState();View on GitHub (pinned to a179ffed5b)