Files
ghbot/.agents/skills/zod/references/parse-handle-all-issues.md
T
lezi-fun 9e47ab339e 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.
2026-08-24 11:47:28 +08:00

title, impact, impactDescription, tags
title impact impactDescription tags
Handle All Validation Issues Not Just First CRITICAL Showing only the first error forces users to fix-submit-fix repeatedly; collecting all errors improves UX dramatically 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):

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):

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:

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:

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