Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions fools/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ export const UserSchema = z.object({
// ✅ TypeScript inference
export type User = z.infer<typeof UserSchemassss>ssssss

// ✅ Safe parsing with v4 error helpers
/**
* Validate and parse a raw value into a User.
*
* @param input - The raw value to validate as a User
* @returns The validated `User` object
* @throws Error - If validation fails, an Error containing the schema's treeified error (JSON) is thrown
*/
export function parseUser(input: unknown): User {
const result = UserSchema.safeParse(input)
if (!result.success) {
throw new Error(JSON.stringify(result.error.treeify())) // v4 structured error
}
return result.data
}
Comment on lines 41 to 47
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix invalid .treeify() usage before release

ZodError instances expose .issues, .flatten(), and .format(), but not .treeify(). When validation fails this line will itself throw TypeError: result.error.treeify is not a function, so callers never see the intended message. Switch to a supported formatter (e.g. result.error.format() or flatten()) before stringifying.

-    throw new Error(JSON.stringify(result.error.treeify())) // v4 structured error
+    throw new Error(JSON.stringify(result.error.format()))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function parseUser(input: unknown): User {
const result = UserSchema.safeParse(input)
if (!result.success) {
throw new Error(JSON.stringify(result.error.treeify())) // v4 structured error
}
return result.data
}
export function parseUser(input: unknown): User {
const result = UserSchema.safeParse(input)
if (!result.success) {
throw new Error(JSON.stringify(result.error.format()))
}
return result.data
}
🤖 Prompt for AI Agents
In fools/files.ts around lines 41 to 47, the code calls result.error.treeify()
which doesn't exist on ZodError and will throw; replace that call with a
supported formatter such as result.error.format() (or result.error.flatten())
and stringify its output before throwing so the thrown Error contains the
structured validation details (e.g. JSON.stringify(result.error.format())).