feat: sync ghbot-Nodeloc v1.2.0 capabilities into upstream
Merges all 33 commits from lza6/ghbot-Nodeloc (v1.0.0 through v1.2.0) while keeping both sides' features in every conflicted file: - EventRouter dispatch extracted from runReview.ts (7.1), with the runtime environment block preserved on the review-start comment - Unified command ack messages (6.3) combined with the collapsed runtime environment block and bot signature on /recheck replies - Status banner and collapsible unposted findings in review bodies (6.1) - Centralized runtime directories behind GHBOT_RUNTIME_DIR (D-13); webhook knowledge cache now lives under tempRootDirectory() - Production hardening for merge races, timeouts, webhook ops; atomic temp-file rename for R2 cache restores kept from upstream - Webhook parity retained: triage events gated by WEBHOOK_TRIAGE_ENABLED, read-only command guidance, repository knowledge injection, runtime environment block on webhook chat replies - Sanitization/secret redaction centralization, error-aware retry, duplicate merge prevention, in-process webhook retries, /metrics - Infra: eslint/prettier gates with CI verify workflow, docs archives typecheck, eslint, prettier format:check, and 164 tests all pass.
This commit is contained in:
commit
9e47ab339e
180 files changed
+15130
-1209
No files matched your search
@@ -0,0 +1,126 @@
|
||||
---
|
||||
title: Handle All Validation Issues Not Just First
|
||||
impact: CRITICAL
|
||||
impactDescription: Showing only the first error forces users to fix-submit-fix repeatedly; collecting all errors improves UX dramatically
|
||||
tags: parse, errors, issues, user-experience
|
||||
---
|
||||
|
||||
## Handle All Validation Issues Not Just First
|
||||
|
||||
Zod collects all validation failures, not just the first one. When displaying errors to users, show all issues so they can fix everything at once instead of playing whack-a-mole with one error at a time.
|
||||
|
||||
**Incorrect (showing only first error):**
|
||||
|
||||
```typescript
|
||||
import { z } from "zod";
|
||||
|
||||
const formSchema = z.object({
|
||||
email: z.string().email("Invalid email"),
|
||||
password: z.string().min(8, "Password must be 8+ characters"),
|
||||
confirmPassword: z.string(),
|
||||
age: z.number().min(18, "Must be 18 or older")
|
||||
});
|
||||
|
||||
function validateForm(data: unknown) {
|
||||
const result = formSchema.safeParse(data);
|
||||
|
||||
if (!result.success) {
|
||||
// Only shows first error - terrible UX
|
||||
return { error: result.error.issues[0].message };
|
||||
}
|
||||
|
||||
return { data: result.data };
|
||||
}
|
||||
|
||||
// User submits empty form
|
||||
validateForm({});
|
||||
// Returns: { error: 'Invalid email' }
|
||||
// User fixes email, submits again
|
||||
// Returns: { error: 'Password must be 8+ characters' }
|
||||
// User fixes password, submits again...
|
||||
// 4 round trips to fix 4 errors!
|
||||
```
|
||||
|
||||
**Correct (showing all errors):**
|
||||
|
||||
```typescript
|
||||
import { z } from "zod";
|
||||
|
||||
const formSchema = z.object({
|
||||
email: z.string().email("Invalid email"),
|
||||
password: z.string().min(8, "Password must be 8+ characters"),
|
||||
confirmPassword: z.string(),
|
||||
age: z.number().min(18, "Must be 18 or older")
|
||||
});
|
||||
|
||||
function validateForm(data: unknown) {
|
||||
const result = formSchema.safeParse(data);
|
||||
|
||||
if (!result.success) {
|
||||
// Collect errors by field for form display
|
||||
const fieldErrors: Record<string, string[]> = {};
|
||||
|
||||
for (const issue of result.error.issues) {
|
||||
const field = issue.path.join(".");
|
||||
if (!fieldErrors[field]) {
|
||||
fieldErrors[field] = [];
|
||||
}
|
||||
fieldErrors[field].push(issue.message);
|
||||
}
|
||||
|
||||
return { errors: fieldErrors };
|
||||
}
|
||||
|
||||
return { data: result.data };
|
||||
}
|
||||
|
||||
// User submits empty form
|
||||
validateForm({});
|
||||
// Returns: {
|
||||
// errors: {
|
||||
// email: ['Invalid email'],
|
||||
// password: ['Password must be 8+ characters'],
|
||||
// confirmPassword: ['Required'],
|
||||
// age: ['Expected number, received undefined']
|
||||
// }
|
||||
// }
|
||||
// User sees ALL errors, fixes everything, submits once!
|
||||
```
|
||||
|
||||
**Using flatten() for simpler error structure:**
|
||||
|
||||
```typescript
|
||||
const result = formSchema.safeParse(data);
|
||||
|
||||
if (!result.success) {
|
||||
const flattened = result.error.flatten();
|
||||
// {
|
||||
// formErrors: [], // Top-level errors
|
||||
// fieldErrors: {
|
||||
// email: ['Invalid email'],
|
||||
// password: ['Password must be 8+ characters'],
|
||||
// ...
|
||||
// }
|
||||
// }
|
||||
return { errors: flattened.fieldErrors };
|
||||
}
|
||||
```
|
||||
|
||||
**With React Hook Form integration:**
|
||||
|
||||
```typescript
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
const form = useForm({
|
||||
resolver: zodResolver(formSchema)
|
||||
// All errors are automatically collected and displayed
|
||||
});
|
||||
```
|
||||
|
||||
**When NOT to use this pattern:**
|
||||
|
||||
- Rate-limited APIs where you want to fail fast on first error
|
||||
- Large batch processing where full validation is expensive
|
||||
|
||||
Reference: [Zod Error Handling](https://zod.dev/error-handling)
|
||||
Reference in new issue
Block a user