-
Notifications
You must be signed in to change notification settings - Fork 238
Refactor app validation errors: result-based parsing, structured error data #7126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3bf51b5
86abe0f
3249375
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,9 @@ | ||||||||||||||||||||
| interface ParsedIssue { | ||||||||||||||||||||
| path?: (string | number)[] | ||||||||||||||||||||
| message: string | ||||||||||||||||||||
| code?: string | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| interface UnionError { | ||||||||||||||||||||
| issues?: {path?: (string | number)[]; message: string}[] | ||||||||||||||||||||
| name: string | ||||||||||||||||||||
|
|
@@ -65,6 +71,23 @@ function formatErrorLine(issue: {path?: (string | number)[]; message?: string}, | |||||||||||||||||||
| return `${indent}• [${path}]: ${message}\n` | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export function parseStructuredErrors(issues: ExtendedZodIssue[]): ParsedIssue[] { | ||||||||||||||||||||
| const result: ParsedIssue[] = [] | ||||||||||||||||||||
| for (const issue of issues) { | ||||||||||||||||||||
| if (issue.code === 'invalid_union' && issue.unionErrors) { | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐛 Bug: When Suggestion: Add a fallback when
Suggested change
|
||||||||||||||||||||
| const bestVariant = findBestMatchingVariant(issue.unionErrors) | ||||||||||||||||||||
| if (bestVariant?.issues?.length) { | ||||||||||||||||||||
| for (const nested of bestVariant.issues) { | ||||||||||||||||||||
| result.push({path: nested.path, message: nested.message, code: issue.code}) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| result.push({path: issue.path, message: issue.message ?? 'Unknown error', code: issue.code}) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| return result | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export function parseHumanReadableError(issues: ExtendedZodIssue[]) { | ||||||||||||||||||||
| let humanReadableError = '' | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Suggestion:
parseHumanReadableErroris no longer imported by any production code — the only references are inerror-parsing.ts(definition) anderror-parsing.test.ts(tests). It was replaced byparseStructuredErrorsinloader.ts. Keeping dead code with active tests is worse than no code — it signals the function is important when it isn't, and the two parallel implementations of union-variant error parsing have subtly different fallback behavior (see the missing fallback bug above). If it's intentionally retained for a follow-up PR, a comment noting the planned usage would prevent someone from removing it prematurely.Suggestion: Verify with a grep that there are no remaining callers, then remove
parseHumanReadableError,formatErrorLine, and their tests. If kept intentionally, add a comment explaining why.