* Parse and validate a JSON string against the hook output Zod schema. * Returns the validated output or formatted validation errors.
( jsonString: string, )
| 380 | * Returns the validated output or formatted validation errors. |
| 381 | */ |
| 382 | function 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 | |
| 399 | function parseHookOutput(stdout: string): { |
| 400 | json?: HookJSONOutput |
no test coverage detected