diegosouzapw/OmniRoute · error · Error
Failed to compile hook "${hookName}": ${message}
Error message
Failed to compile hook "${hookName}": ${message} What it means
Error "Failed to compile hook "${hookName}": ${message}" thrown in diegosouzapw/OmniRoute.
Source
Thrown at src/lib/middleware/registry.ts:123
URLSearchParams,
// Deliberately absent: process, require, module, exports, global,
// globalThis, fetch, Buffer, setTimeout/setInterval, __dirname, __filename.
};
}
function compileHookCode(code: string, hookName: string): HookMiddleware {
// Compile-once: parse the source into a reusable vm.Script. This throws on
// syntax errors at registration time (preserving the original behavior) and
// is cached in the returned closure so each execution only pays for a fresh
// minimal context, not re-parsing.
let script: vm.Script;
try {
script = new vm.Script(`(async () => { ${code} })();`, {
filename: `omniroute-hook:${hookName}`,
});
} catch (err: unknown) {
const message = err instanceof Error ? err.message : "Compilation error";
throw new Error(`Failed to compile hook "${hookName}": ${message}`);
}
return async (context: PreRequestHookContext): Promise<HookResult> => {
const sandbox = createHookSandbox(context);
const vmContext = vm.createContext(sandbox, {
codeGeneration: { strings: false, wasm: false },
});
let timer: ReturnType<typeof setTimeout> | undefined;
try {
// The `vm` timeout only interrupts *synchronous* runaway code; the
// Promise.race below bounds async work that never settles.
const execution: unknown = script.runInContext(vmContext, {
timeout: HOOK_EXECUTION_TIMEOUT_MS,
});
const timeoutGuard = new Promise<never>((_resolve, reject) => {
timer = setTimeout(() => {View on GitHub (pinned to a179ffed5b)
When it happens
Trigger: Thrown at src/lib/middleware/registry.ts:123 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/249f967276b17c73.
Report an issue: GitHub.