{"record":{"id":"249f967276b17c73","repo":"diegosouzapw/OmniRoute","slug":"failed-to-compile-hook-hookname-message","errorCode":null,"errorMessage":"Failed to compile hook \"${hookName}\": ${message}","messagePattern":"Failed to compile hook \"(.+?)\": (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/middleware/registry.ts","lineNumber":123,"sourceCode":"    URLSearchParams,\n    // Deliberately absent: process, require, module, exports, global,\n    // globalThis, fetch, Buffer, setTimeout/setInterval, __dirname, __filename.\n  };\n}\n\nfunction compileHookCode(code: string, hookName: string): HookMiddleware {\n  // Compile-once: parse the source into a reusable vm.Script. This throws on\n  // syntax errors at registration time (preserving the original behavior) and\n  // is cached in the returned closure so each execution only pays for a fresh\n  // minimal context, not re-parsing.\n  let script: vm.Script;\n  try {\n    script = new vm.Script(`(async () => { ${code} })();`, {\n      filename: `omniroute-hook:${hookName}`,\n    });\n  } catch (err: unknown) {\n    const message = err instanceof Error ? err.message : \"Compilation error\";\n    throw new Error(`Failed to compile hook \"${hookName}\": ${message}`);\n  }\n\n  return async (context: PreRequestHookContext): Promise<HookResult> => {\n    const sandbox = createHookSandbox(context);\n    const vmContext = vm.createContext(sandbox, {\n      codeGeneration: { strings: false, wasm: false },\n    });\n\n    let timer: ReturnType<typeof setTimeout> | undefined;\n    try {\n      // The `vm` timeout only interrupts *synchronous* runaway code; the\n      // Promise.race below bounds async work that never settles.\n      const execution: unknown = script.runInContext(vmContext, {\n        timeout: HOOK_EXECUTION_TIMEOUT_MS,\n      });\n\n      const timeoutGuard = new Promise<never>((_resolve, reject) => {\n        timer = setTimeout(() => {","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/middleware/registry.ts#L105-L141","documentation":"Error \"Failed to compile hook \"${hookName}\": ${message}\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/lib/middleware/registry.ts:123 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}