Use safeParse instead of parse for zod schemas to improve error reporting
The error reporting on zod parsing failures right now reports "Invalid response schema," which made debugging some stagehand test failures difficult. We can improve error handling by using a pattern like this:
const result = schema.safeParse(data);
if (!result.success) { // log or rethrow with detail throw new MyCustomError(result.error.format()); }
const parsed = result.data;
This would allow you to get more explicit guidance on why Zod schema parsing failed - example:
{ name: { _errors: ['Required'] }, age: { _errors: ['Expected number, received string'] }, _errors: [] }
Thanks for the feedback!! We can certainly take this on, unless someone else wants to handle this :)
I'm happy to take this!
Have a first iteration here: #690
@kamath can you review this please?