feat(shared): add safeCreateHook utility for error-safe hook creation

This commit is contained in:
YeonGyu-Kim
2026-02-07 13:32:45 +09:00
parent 1c0b41aa65
commit f9742ddfca
3 changed files with 98 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
import { log } from "./logger"
interface SafeCreateHookOptions {
enabled?: boolean
}
export function safeCreateHook<T>(
name: string,
factory: () => T,
options?: SafeCreateHookOptions,
): T | null {
const enabled = options?.enabled ?? true
if (!enabled) {
return factory() ?? null
}
try {
return factory() ?? null
} catch (error) {
log(`[safe-create-hook] Hook creation failed: ${name}`, { error })
return null
}
}