MCPcopy Create free account
hub / github.com/codeaashu/claude-code / validateHookJson

Function validateHookJson

src/utils/hooks.ts:382–397  ·  view source on GitHub ↗

* Parse and validate a JSON string against the hook output Zod schema. * Returns the validated output or formatted validation errors.

(
  jsonString: string,
)

Source from the content-addressed store, hash-verified

380 * Returns the validated output or formatted validation errors.
381 */
382function validateHookJson(
383 jsonString: string,
384): { json: HookJSONOutput } | { validationError: string } {
385 const parsed = jsonParse(jsonString)
386 const validation = hookJSONOutputSchema().safeParse(parsed)
387 if (validation.success) {
388 logForDebugging('Successfully parsed and validated hook JSON output')
389 return { json: validation.data }
390 }
391 const errors = validation.error.issues
392 .map(err => ` - ${err.path.join('.')}: ${err.message}`)
393 .join('\n')
394 return {
395 validationError: `Hook JSON output validation failed:\n${errors}\n\nThe hook's output was: ${jsonStringify(parsed, null, 2)}`,
396 }
397}
398
399function parseHookOutput(stdout: string): {
400 json?: HookJSONOutput

Callers 2

parseHookOutputFunction · 0.85
parseHttpHookOutputFunction · 0.85

Calls 3

jsonParseFunction · 0.85
logForDebuggingFunction · 0.85
jsonStringifyFunction · 0.85

Tested by

no test coverage detected